Is there a way to specify that a particular enricher should only be used for a specific sink?

Viewed 151

I have multiple sinks configured and I have a cuustom enricher that I want to apply ONLY to text based sinks like Console and RollingFile.

Is there a way to do this serilog ?

1 Answers

Yes, a sub-logger can do this:

Log.Logger = new LoggerConfiguration()
    .WriteTo.Seq("https://your-server") // Not enriched
    .WriteTo.Logger(lc => lc
        .Enrich.WithProperty("SomeProperty", 42)
        .WriteTo.Console()              // Enriched
        .WriteTo.File("logs.txt"))      // Enriched
    .CreateLogger();
Related