Reputation: 3856
I would like to have Serilog write to a new file with an incremented suffix every time a new Logger is created.
For example:
Basically, I want the behavior posted by the OP on this github issue: https://github.com/serilog/serilog-sinks-rollingfile/issues/9
I want was the OP was trying to get rid of.
When I use this code below, only one file is generated even though the logger is new
ed up multiple times:
var log = new LoggerConfiguration()
.WriteTo.RollingFile(@"C:\temp\testlog\log-{Date}.txt")
.CreateLogger();
log.Debug("Created logger...");
Upvotes: 2
Views: 3558
Reputation: 30016
I suggest you check whether the generated one file
contains Created logger...
.
For LoggerConfiguration
, its default LogEventLevel
is Serilog.Events.LogEventLevel.Information
which means your log.Debug("Created logger...");
code will not create log records.
I suggest you make a test with code below:
var log = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.RollingFile(@"C:\Windows\Temp\testlog\log-{Date}.txt")
.CreateLogger();
log.Debug("Created logger1...");
var log1 = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.RollingFile(@"C:\Windows\Temp\testlog\log-{Date}.txt", Serilog.Events.LogEventLevel.Debug)
.CreateLogger();
log1.Debug("Created logger2...");
Above code will create two files, if you require the file name exactly like log_001.txt
and log_002.txt
, you need to implement your own sink
, check this discussion Filename without date #59.
Upvotes: 3