In Serilog, you can easily enable rolling log files:
Log.Logger = new LoggerConfiguration()
.WriteTo.File("log-.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
This will create a new log file every day in the following format:
log-20200214.txtlog-20200215.txtlog-20200216.txtMy question: is it possible to customize where the date is placed in the file name, and to customize how the date is formatted?
e.g. I want the file names to look like this:
2020-02-14-log.txt2020-02-15-log.txt2020-02-16-log.txtI was hoping replacing "log-.txt" with "{Date:yyyy-MM-dd}-log.txt" would work, but it doesn't.
This is not currently supported by the Serilog.Sinks.File sink. If you really want this feature, you can try to send a pull-request, or fork the repository and use your own custom implementation.
Links you might be interested in:
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