问题描述
我正在使用Serilog-RollingFile Sink,但是它将所有数据存储在一个文件中一天.在我的应用程序中,一天要写入1 GB的日志.所以我想根据日期和大小滚动日志文件.
I am using Serilog - RollingFile Sink, but it stores all data in a single file for a day.In my application, 1 GB log is written in a day. So I want to roll log file on the basis of date and size.
如何配置RollingFile Sink根据日期和大小滚动文件?
How can I configure RollingFile Sink to roll files based on date and size?
推荐答案
现在不推荐使用Serilog.Sinks.RollingFile软件包,而推荐使用Serilog.Sinks.File(请参阅github项目自述文件简介). Serilog.Sinks.File软件包已升级以支持文件滚动.您可以使用以下Serilog配置来启用按时间和大小滚动:
Nowadays Serilog.Sinks.RollingFile package is deprecated in favor of Serilog.Sinks.File (see the github project readme intro). Serilog.Sinks.File package has been upgraded to support file rolling.You can use the following Serilog config to enable rolling both by time and size:
"Serilog": {
"Using": ["Serilog.Sinks.File"],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "logs/log.txt",
"rollingInterval": "Day",
"rollOnFileSizeLimit": true,
"fileSizeLimitBytes": "512",
"retainedFileCountLimit": 3,
"formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog"
}
}
]
}
然后您将得到如下内容:
Then you will get something like this:
这篇关于Serilog-RollingFile Sink不会根据日期和大小滚动文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!