serilog-settings-configuration icon indicating copy to clipboard operation
serilog-settings-configuration copied to clipboard

configureLogger doesn't work for published app

Open SvetlanaLevi opened this issue 2 years ago • 1 comments

I need to specify different filters for each sink and example above is working correctly in debug mode, but after publishing application as self-contained logs failed to write.

{
  "Serilog": {
    "MinimumLevel": "Debug",
    "Using": [
      "Serilog.Sinks.Console",
      "Serilog.Sinks.File",
      "Serilog.Expressions"
    ],
    "WriteTo": [
      {
        "Name": "Logger",
        "Args": {
          "configureLogger": {
            "Filter": [
              {
                "Name": "ByExcluding",
                "Args": {
                  "expression": "StartsWith(SourceContext, 'System.Net.Http.HttpClient.HttpMarkingService.LogicalHandler')"
                }
              }
            ],
            "WriteTo": [
              {
                "Name": "Console",
                "Args": {
                  "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} {NewLine}"
                }
              }
            ]
          }
        }
      },
      {
        "Name": "Logger",
        "Args": {
          "configureLogger": {
            "WriteTo": [
              {
                "Name": "File",
                "Args": {
                  "path": "log.txt",
                  "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} <s:{SourceContext}>{NewLine}{Exception}"
                }
              }
            ]
          }
        }
      }
    ]
  }
}

Without nested "WriteTo" sections it works fine.

SvetlanaLevi avatar Nov 28 '22 14:11 SvetlanaLevi