I'm using Serliog in a .Net WPF application.
Is there a way that I can "tail" (delete) the log files automatically when they are over N days old?
Specifies the frequency at which the log file should roll. Namespace: Serilog.Sinks.AmazonS3.
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.
Serilog sink that writes to console with high-performance non-blocking output. Supports plaintext and JSON output but does not support themes and colors. This sink uses a background channel with a single text buffer and async writes to remove all blocking and lock contention to the console output stream.
According to the documentation, the default value of retainedFileCountLimit
is 31 so only the most recent 31 files are kept by default.
To change the amount of files kept in code:
var log = new LoggerConfiguration()
.WriteTo.File("log.txt", retainedFileCountLimit: 42)
.CreateLogger();
pass null
to remove the limit.
In XML <appSettings>
configuration:
<appSettings>
<add key="serilog:using:File" value="Serilog.Sinks.File" />
<add key="serilog:write-to:File.path" value="log.txt" />
<add key="serilog:write-to:File.retainedFileCountLimit" value="42"/>
</appSettings>
and pass an empty string to remove the limit.
In JSON appsettings.json
configuration
{
"Serilog": {
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "log.txt",
"retainedFileCountLimit": "42"
}
}
]
}
}
and pass an empty string to remove the limit. Note that I have not tested the JSON configuration.
https://github.com/serilog/serilog-sinks-rollingfile/blob/dev/README.md Look there. You can configure autocreation of a new log file every day and also you can set how many of them you want to be kept
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