简体   繁体   English

如何使用Serilog RollingFile接收器启用多个文件?

[英]How to enable multiple files with Serilog RollingFile sink?

I've setup my sink as follows: 我将水槽设置如下:

"WriteTo": [
  {
    "Name": "RollingFile",
    "Args": {
      "pathFormat": "log-{Date}.log",
      "fileSizeLimitBytes": 20000000,
    }
  }
]

My understanding was that once the log-06042019.log file reaches 20000000 bytes, it will start logging to log-06042019-001.log , then to log-06042019-002.log and so on. 我的理解是,一旦log-06042019.log文件达到20000000个字节,它会自动开始记录到log-06042019-001.log ,然后log-06042019-002.log等。

But that doesn't happen. 但这不会发生。 It simply stops logging until the next day. 它只是停止记录直到第二天。
Am I missing something simple in order to enable the rolling characteristics of this sink? 我是否为了使水槽具有滚动特性而缺少一些简单的东西?

You shouldn't use the RollingFile sink anymore. 您不应该再使用RollingFile接收器。 Instead, use the File Sink . 而是使用File Sink

The file sink has a setting to roll over at a certain size. 文件接收器具有可以以特定大小滚动的设置。 Here's the C# configuration: 这是C#配置:

.WriteTo.File("log.txt", rollOnFileSizeLimit: true)

or appsettings.json: 或appsettings.json:

{
  "Serilog": {
    "WriteTo": [
      { "Name": "File", "Args": { "path": "log.txt", "rollOnFileSizeLimit": "true" } }
    ]
  }
}

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

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