I'm using Serilog with ASP.NET Core 2.1, and configure it via the appsettings.json
.
The default template doesn't include {SourceContext}
, so I use my own template which includes it. But I also want structured logging with JSON.
I read somewhere in the Serilog wiki that I can't specify formatter
(for JSON output) and outputTemplate
at the same time.
So I can't do this for example:
"outputTemplate": "{Timestamp:yyyy-MM-dd} {Level:u3} {SourceContext} {Message:lj}{NewLine}{Exception}",
"formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact"
So how can I get JSON output, but also get the SourceContext
data that I need?