cs-codex-dist-tests/Logging/FixtureLog.cs

53 lines
1.4 KiB
C#
Raw Normal View History

2023-04-14 12:53:39 +00:00
using NUnit.Framework;
namespace Logging
{
public class FixtureLog : BaseLog
{
private readonly DateTime start;
private readonly string fullName;
2023-04-25 09:31:15 +00:00
private readonly LogConfig config;
2023-04-14 12:53:39 +00:00
public FixtureLog(LogConfig config)
2023-04-25 09:31:15 +00:00
: base(config.DebugEnabled)
2023-04-14 12:53:39 +00:00
{
start = DateTime.UtcNow;
var folder = DetermineFolder(config);
var fixtureName = GetFixtureName();
2023-04-14 12:53:39 +00:00
fullName = Path.Combine(folder, fixtureName);
2023-04-25 09:31:15 +00:00
this.config = config;
2023-04-14 12:53:39 +00:00
}
public TestLog CreateTestLog()
{
2023-04-25 09:31:15 +00:00
return new TestLog(fullName, config.DebugEnabled);
2023-04-14 12:53:39 +00:00
}
protected override LogFile CreateLogFile()
{
return new LogFile(fullName, "log");
}
private string DetermineFolder(LogConfig config)
{
return Path.Join(
config.LogRoot,
$"{start.Year}-{Pad(start.Month)}",
Pad(start.Day));
}
private string GetFixtureName()
{
var test = TestContext.CurrentContext.Test;
var className = test.ClassName!.Substring(test.ClassName.LastIndexOf('.') + 1);
return $"{Pad(start.Hour)}-{Pad(start.Minute)}-{Pad(start.Second)}Z_{className.Replace('.', '-')}";
}
private static string Pad(int n)
{
return n.ToString().PadLeft(2, '0');
}
}
}