Reputation: 1038
The title basically. I want Serilog to overwrite the log file on rollover and not create log-001, log-002 etc. There doesn't seem to be any option to do that from what I see in the references.
Of course it's possible to query the file size and delete it if it grows too big. But is there any way to handle this from within Serilog?
Upvotes: 0
Views: 1345
Reputation: 35075
Update: It was a rubbish answer, but with Nicholas Blumhardt's comment I think I can make it better
Check out FileLoggerConfigurationExtensions
// rollOnFileSizeLimit:
// If true, a new file will be created when the file size limit is reached. Filenames
// will have a number appended in the format _NNN, with the first filename given
// no number.
I think combining retainedFileCountLimit
, fileSizeLimitBytes
and rollOnFileSizeLimit
you could get close to one file :)
The following configuration should produce 2 files:
.WriteTo.File(
logFilePath,
rollOnFileSizeLimit: true,
fileSizeLimitBytes: 1_000_000,
retainedFileCountLimit: 2))
Upvotes: 1