I have an ASP.Net Core 2 web application where I'm trying to configure SeriLog to output in JSON format, configured via an appsettings.json file. I cannot get this to work with either the standard Serilog.Formatting.Json.JsonFormatter or the compact Serilog.Formatting.Compact.CompactJsonFormatter.
I see there's a similar question asked here, but there seems to be no conclusive answer using appsettings.json, and the thread has gone quiet for over a year (and I don't have enough reputation to comment to nudge further responses).
I'm using the following SeriLog packages:
- Serilog.AspNetCore - 2.1.0
- Serilog.Enrichers.Environment - 2.1.2
- Serilog.Enrichers.Thread - 3.0.0
- Serilog.Formatting.Compact - 1.0.0
- Serilog.Settings.Configuration - 2.4.0
- Serilog.Sinks.RollingFile - 3.3.0
The SeriLog section of my appsettings.json file reads:
"Serilog": {
"Using": ["Serilog.Sinks.RollingFile"],
"MinimumLevel": {
"Default": "Verbose",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{
"Name": "RollingFile",
"Args": {
"pathFormat": "C:\\Logs\\MLSBPortal-{Date}.txt",
"formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact",
"restrictedToMinimumLevel": "Debug",
"retainedFileCountLimit": "10",
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] [{ThreadId}] [{SourceContext}] [{SessionId}] [{UserName}]: {Message}{NewLine}{Exception}"
}
}
],
with the formatter line modified to the following when testing with the default JSON formatter:
"formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog",
As suggested in multiple other places.
My output is being written fine, but the formatter setting does not appear to be making any difference to the output.
Am I doing something wrong here, or is this functionality not implemented via a configuration file read yet?
Thanks in advance for any help.