I'm a newbie to C#... We're using Serilog to record ILogger log records. For my test cases, I'd like to pass a log filename to Serilog File sink and have it not insert YYYYMMDD into the filename. So far, I have not found a way to get Serilog to not insert the date into the log filename. Below are abbreviated code snippets to demonstrate the point:
public static class Log
{
private static readonly ConcurrentDictionary<string, Lazy<ILogger>> fileLogs = new ConcurrentDictionary<string, Lazy<ILogger>>();
public static ILogger File(string path)
{
var filePath = string.IsNullOrEmpty(path)
? $"{Assembly.GetEntryAssembly().GetName().Name}_{UnixEpoch.MillisecondsNow}.log"
: path;
var fileInfo = new FileInfo(filePath);
return fileLogs.GetOrAdd(fileInfo.FullName, name => new Lazy<ILogger>(() =>
{
fileInfo.Directory.Create();
return LoggerFactory
.Create(builder => builder.AddFile(filePath))
.CreateLogger("File");
})).Value;
}
}
public void CreateFileLog()
{
var log = Log.File("./test.log");
log.LogInformation("Sample log record.");
}
The output filename will be: ./test20220517.log
How do I setup Serilog File sink so it doesn't insert the date into the log filename?