简体   繁体   English

Serilog 异步文件日志记录 - 如何添加滚动

[英]Serilog Async File logging - how to add rolling

I am using latest Serilog.File 4.1.0 and Serilog.Sinks.Async .我正在使用最新Serilog.File 4.1.0Serilog.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. File接收器支持滚动文件。 Just define your rolling policies .只需定义您的 滚动策略

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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