Serilog rollover by datetime stamp

24 Views Asked by At

we are running windows service account, which creating serilog log with timestamp in the log file. we are using the following code to create log file based on datetime.

.WriteTo.FileWithTimestamp( path: logFilePath, rollOnFileSizeLimit: bool.Parse(Configuration.Value["File-rollOnFileSizeLimit"]!), fileSizeLimitBytes: int.Parse(Configuration.Value["File-fileSizeLimitBytes"]!), shared: bool.Parse(Configuration.Value["File-shared"]!), outputTemplate: Configuration.Value["File-outputTemplate"]!, restrictedToMinimumLevel: fileRestrictedToMinimumLevel )

Config setting for File-outputTemplate:

"File-outputTemplate": "{Timestamp:yy-MM-dd HH:mm:ss.fff} {MachineName} [{Level:u3}][{ThreadId:d3}] {Message}{NewLine}{Exception}",

var logFilePath = $"test_log.{{Timestamp:yyyy-MM-dd}}");

Since, our server will never stop . The everyday log are written to the same log file instead of new file based on the date in which the process is running.

Our Application cannot be restarted everyday. what is our options.

Thanks

Log file with datetime everyday without starting the service.

0

There are 0 best solutions below