Skip to content

Date-driven (rather than count-driven) file retention option #39

Closed
@stephenpatten

Description

@stephenpatten

Nick,

Aside from the fact that I (we) log too much, how do I keep all the log files created per day. It looks like we are only keeping the last 31 files. My thinking would be that with my config that the time period would trump the file size rolling behaviour. i.e. I should have 31 calendar days of logs and each day may have hundreds of files that rolled on size.. Hope that make some sense.

Below you'll find my logger bootstrap and the packages I'm using.

Thank you,
Stephen

var filePath =
	$"{ConfigurationManager.AppSettings["LogFileBaseDir"]}\\ExternalFields_{Environment.MachineName}_.txt";

const string Workflow_Serilog_V6 = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}|{Level:u3}|{CorrelationId}|{MachineName}|{Application}|{ProcessId}|{ThreadId}|{SourceContext:l}|{Message}|{NewLine}{Exception}";

Log.Logger = new LoggerConfiguration()
	.ReadFrom.AppSettings()
	.Enrich.FromLogContext()
	.Enrich.WithMachineName()
	.Enrich.WithProcessId()
	.Enrich.WithThreadId()
	.Enrich.WithProperty("Application", "ExternalFields")
	/*https://github.com/serilog/serilog-sinks-file*/
	.WriteTo.Async(a => 
			a.File(filePath, 
			outputTemplate: Workflow_Serilog_V6, 
			rollingInterval: RollingInterval.Day, 
			rollOnFileSizeLimit: true, 
			fileSizeLimitBytes: 104857600, 
			buffered: true,
			flushToDiskInterval: TimeSpan.FromMilliseconds(500)))
	.CreateLogger();

image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions