Search code examples
serilogappsettings

Can enricher be applied to specific sink via json configuration?


Having following config:

    "Enrich": "SuperCoolEnricher",
    
    "WriteTo:File": {
      "Name": "File",
      "Args": {...},
    },

    "WriteTo:Seq": {
      "Name": "Seq",
      "Args": {...},
    }

all the sinks are enriched. I would like to enrich the File one only, is there something I could do in the json config? Like, e.g.:

    "WriteTo:File": {
      "Name": "File",
      "Args": {...},
      "Enrich": "SuperCoolEnricher",
    },

    "WriteTo:Seq": {
      "Name": "Seq",
      "Args": {...},
    }

(which is not working)...


Solution

  • There is a concept of sub-loggers, which actually are usable for this:

        "WriteTo:FileLogger": {
          "Name": "Logger",
          "Args": {
            "configureLogger": {
              "WriteTo:File": {
                "Name": "File",
                "Args": {
                  "path": "Test-.log",
                  "restrictedToMinimumLevel": "Debug"
                }
              },
              "Enrich:File": "SuperCoolEnricher"
            }
          }
        }