Adds log tag to each log file.
This commit is contained in:
parent
87d346ee20
commit
07776dc6fb
|
@ -21,7 +21,11 @@ namespace Logging
|
|||
{
|
||||
get
|
||||
{
|
||||
if (logFile == null) logFile = new LogFile(GetFullName(), "log");
|
||||
if (logFile == null)
|
||||
{
|
||||
logFile = new LogFile(GetFullName(), "log");
|
||||
WriteLogTag();
|
||||
}
|
||||
return logFile;
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +77,14 @@ namespace Logging
|
|||
return new LogFile($"{GetFullName()}_{GetSubfileNumber()}", ext);
|
||||
}
|
||||
|
||||
private void WriteLogTag()
|
||||
{
|
||||
var runId = NameUtils.GetRunId();
|
||||
var category = NameUtils.GetCategoryName();
|
||||
var name = NameUtils.GetTestMethodName();
|
||||
LogFile.WriteRaw($"{runId} {category} {name}");
|
||||
}
|
||||
|
||||
private string ApplyReplacements(string str)
|
||||
{
|
||||
foreach (var replacement in replacements)
|
||||
|
|
|
@ -26,6 +26,29 @@ namespace Logging
|
|||
return className.Replace('.', '-');
|
||||
}
|
||||
|
||||
public static string GetCategoryName()
|
||||
{
|
||||
var test = TestContext.CurrentContext.Test;
|
||||
return test.ClassName!.Substring(0, test.ClassName.LastIndexOf('.'));
|
||||
}
|
||||
|
||||
public static string GetTestId()
|
||||
{
|
||||
return GetEnvVar("TESTID");
|
||||
}
|
||||
|
||||
public static string GetRunId()
|
||||
{
|
||||
return GetEnvVar("RUNID");
|
||||
}
|
||||
|
||||
private static string GetEnvVar(string name)
|
||||
{
|
||||
var v = Environment.GetEnvironmentVariable(name);
|
||||
if (string.IsNullOrEmpty(v)) return $"EnvVar'{name}'NotSet";
|
||||
return v;
|
||||
}
|
||||
|
||||
private static string FormatArguments(TestContext.TestAdapter test)
|
||||
{
|
||||
if (test.Arguments == null || !test.Arguments.Any()) return "";
|
||||
|
|
|
@ -21,37 +21,15 @@ namespace Logging
|
|||
Write(new StatusLogJson
|
||||
{
|
||||
time = DateTime.UtcNow.ToString("u"),
|
||||
runid = GetRunId(),
|
||||
runid = NameUtils.GetRunId(),
|
||||
status = resultStatus,
|
||||
testid = GetTestId(),
|
||||
testid = NameUtils.GetTestId(),
|
||||
codexid = codexId,
|
||||
fixturename = fixtureName,
|
||||
testname = GetTestName()
|
||||
testname = NameUtils.GetTestMethodName()
|
||||
});
|
||||
}
|
||||
|
||||
private string GetTestName()
|
||||
{
|
||||
return NameUtils.GetTestMethodName();
|
||||
}
|
||||
|
||||
private string GetTestId()
|
||||
{
|
||||
return GetEnvVar("TESTID");
|
||||
}
|
||||
|
||||
private string GetRunId()
|
||||
{
|
||||
return GetEnvVar("RUNID");
|
||||
}
|
||||
|
||||
private string GetEnvVar(string name)
|
||||
{
|
||||
var v = Environment.GetEnvironmentVariable(name);
|
||||
if (string.IsNullOrEmpty(v)) return $"'{name}' not set!";
|
||||
return v;
|
||||
}
|
||||
|
||||
private void Write(StatusLogJson json)
|
||||
{
|
||||
try
|
||||
|
|
Loading…
Reference in New Issue