AngryHacker
AngryHacker

Reputation: 61636

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.

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?

Upvotes: 1

Views: 1139

Answers (1)

mason
mason

Reputation: 32703

You shouldn't use the RollingFile sink anymore. Instead, use the File Sink.

The file sink has a setting to roll over at a certain size. Here's the C# configuration:

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

or appsettings.json:

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

Upvotes: 2

Related Questions