pantonis
pantonis

Reputation: 6487

Serilog Async File logging - how to add rolling

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();

Upvotes: 3

Views: 11525

Answers (1)

C. Augusto Proiete
C. Augusto Proiete

Reputation: 27878

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();

Upvotes: 8

Related Questions