Serilog Async File logging - how to add rolling

Viewed 5470

I am using latest Serilog.File 4.1.0 and Serilog.Sinks.Async. Async logging works but I want the files to be rolled. How can I enable rolling of files?

I have the following:

 Log.Logger = new LoggerConfiguration()
                .WriteTo.Async(a =>
                {
                    a.File("logs/logs.log");
                })
                .MinimumLevel.Verbose()
                .CreateLogger();
1 Answers

The File Sink has support for Rolling files. Just define your rolling policies.

Log.Logger = new LoggerConfiguration()
    .WriteTo.Async(a =>
    {
        a.File("logs/logs.log", rollingInterval: RollingInterval.Hour); // <<<<<
    })
    .MinimumLevel.Verbose()
    .CreateLogger();
Related