简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM