C#C
C#3y ago
trustie

❔ Serilog file sink from multiple servers has interleaved messages

I have a web app deployed across 10 web servers. They are all configured as such (note, the path below is a shared network path. So they are all pointing to the same log file):

  "Serilog": {
    "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
    "MinimumLevel": "Debug",
    "WriteTo": [
      {
        "Name": "Console"
      },
      {
        "Name": "File",
        "Args": {
          "shared": true,
          "path": "logs/foo_.log",
          "rollingInterval": "Day",
          "retainedFileCountLimit": 7
        }
      }
    ],
    "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
  },


However I'm noticing the log file has interleaved messages:
2023-02-28 00:03:16.105 -06:00 [DBG] Execution plan of result filters (in the following order): ["Microsoft.AspNetCore.Mvc.Infrastructure.C2023-02-28 00:03:16.054 -06:00 [INF] Requ2023-02-28 00:03:16.130 -06:00 [DBG] Execution plan of result filters (in the following order):

Notice the [DBG] and [INF] log levels in the same message, and this here here specifically:
Infrastructure.C2023-02-28 00:03:16.054 -06:00 [INF] Requ2023-02-28 00:03:16.13

How can I prevent this from happening? I thought shared: true was the support Serilog needed to handle this situation?
Was this page helpful?