diff --git a/Logging/BaseLog.cs b/Logging/BaseLog.cs index 14656e3..6ff6da5 100644 --- a/Logging/BaseLog.cs +++ b/Logging/BaseLog.cs @@ -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) diff --git a/Logging/NameUtils.cs b/Logging/NameUtils.cs index 0a5fcbe..aee7d84 100644 --- a/Logging/NameUtils.cs +++ b/Logging/NameUtils.cs @@ -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 ""; diff --git a/Logging/StatusLog.cs b/Logging/StatusLog.cs index 44af462..06c9f22 100644 --- a/Logging/StatusLog.cs +++ b/Logging/StatusLog.cs @@ -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