I am trying to use WriteTo.RollingFile
with Serilog as the following to write one file per day:
var log = new LoggerConfiguration().WriteTo.RollingFile( @"F:\logs\log-{Date}.txt", LogEventLevel.Debug).CreateLogger(); log.Information("this is a log test");
But I am getting a new log file for each log entry during the same day!
How does one configure Serilog to write to a new file every day as to have a have a single log file per day?
And is there any archiving process to delete files older than 7 days?
This package has been deprecated as it is legacy and is no longer maintained.
Serilog is a . NET library that provides diagnostic logging to files, the console, and almost everywhere you would like. Serilog can be used in classic . NET Framework applications and for applications running on the latest and greatest .
Serilog is a structured logging library for Microsoft . NET and has become the preferred logging library for . NET at Checkout.com.. It supports a variety of logging destinations, referred to as Sinks, from standard console and files based sinks to logging services such as Datadog.
By default, serilog will only log to the console.
Try below:
var log = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.File(@"f:\log\log.txt", rollingInterval: RollingInterval.Day) .CreateLogger();
The log file name will be automatically log-20150819.txt etc. You do not need to specify the date.Old files will be cleaned up as per retainedFileCountLimit - default is 31.
Since the posted answer, the method RollingFile
is no longer viable and replaced with File
and options to roll the logs.
Now one must use the standard Serilog.Sinks.File
NuGet package which supports rolling:
.WriteTo.File(path: @"e:\logs\skilliam.log", rollingInterval: RollingInterval.Day, rollOnFileSizeLimit: true, fileSizeLimitBytes: 123456);
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