I want to configure Serilog to create one log file per app run.
File name should be based on current date/time:
1st run: log_20180413_1020.txt
2nd run: log_20180413_1033.txt
I didn't find how to do it in any File sink (Rolling, Alternative..)
Any clue?
Serilog provides sinks for writing log events to storage in various formats. Many of the sinks listed below are developed and supported by the wider Serilog community; please direct questions and issues to the relevant repository. More sinks can be found by searching within the serilog tag on NuGet.
By default, serilog will only log to the console.
This package has been deprecated as it is legacy and is no longer maintained.
Parameter retainedFileCountLimit tells Serilog how many log files you want in any given time. Here it is set to 10. So on 11th day, Serilog will be generating a log as usual. But to keep the log files count to 10, it will delete the day 1 log file.
Configure the Serilog.Sinks.File
sink without any rolling period or size limit, and add the timestamp to the log filename when you configure logging at startup:
string timestamp = DateTime.Now.ToString("yyyyMMdd_HHmm");
var log = new LoggerConfiguration()
.WriteTo.File($"log{timestamp}.txt")
.CreateLogger();
Per the Rolling Policies section of the README:
Specifying both
rollingInterval
androllOnFileSizeLimit
will cause both policies to be applied, while specifying neither will result in all events being written to a single file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With