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

时间:2020-04-08 10:25:55

标签: c# .net .net-core serilog

我正在使用最新的Serilog.File 4.1.0Serilog.Sinks.Async。异步日志记录有效,但我希望文件被滚动。 如何启用文件滚动?

我有以下内容:

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

1 个答案:

答案 0 :(得分:3)

File接收器支持滚动文件。只需定义您的rolling policies

172.17.0.1 - - [08/Apr/2020:19:05:00 +0000] "GET / HTTP/1.1" 403 490 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36"
172.17.0.1 - - [08/Apr/2020:19:05:00 +0000] "GET / HTTP/1.1" 403 490 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36"
[Wed Apr 08 19:05:00.837027 2020] [autoindex:error] [pid 17] [client 172.17.0.1:40036] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.php,index.html) found, and server-generated directory index forbidden by Options directive
[Wed Apr 08 19:05:00.894055 2020] [autoindex:error] [pid 17] [client 172.17.0.1:40036] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.php,index.html) found, and server-generated directory index forbidden by Options directive