Closed denniskrq closed 2 months ago
There's a section in the README that explains why this problem occurs and how to solve it: use named WriteTo
section.
For you, it should look like this in your appsettings.json
file:
{
"WriteTo": {
"FileSink": {
"Name": "File",
"Args": {
"path": "./Logs/testService-.log",
"formatter": {
"type": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact"
},
"rollingInterval": "Day",
"retainedFileCountLimit": 7
}
},
"ConsoleSink": {
"Name": "Console",
"Args": {
"formatter": {
"type": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
}
}
}
}
}
And like this in your appsettings.Development.json
file:
{
"WriteTo": {
"ConsoleSink": {
"Name": "Console",
"Args": {
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} {Properties}{NewLine}{Exception}"
}
}
}
}
I have the following
WriteTo
section configured in my mainappsettings.json
:I have the following
WriteTo
section configured in myappsettings.Development.json
:What I'm observing when I run my service from a local development build is that instead of the plain text template overriding the rendered compact JSON, both of them appears (the template text outputs before the compact JSON). What's the correct way to get this override working with appsettings.json? I would like to be able to centralize all of my settings in the json files rather than needing to do part of it in code