Can't use JSON event formatting with appsettings.json
See original GitHub issueI wanted to log in json files with .Net Core 2.2. However, it writes my logs in a non json format
Here is my appsettings.json file
"Serilog": {
"MinimumLevel": "Fatal",
"WriteTo": [
{
"Name": "Async",
"Args": {
"configure": [
{
"Name": "File",
"Args": {
"path": "..\\Logs\\log.json",
"formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact",
"rollingInterval": "Day",
"retainedFileCountLimit": 5,
"fileSizeLimitBytes": 1073741824,
"rollOnFileSizeLimit": true,
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}{NewLine}"
}
}
]
}
}
],
"Properties": {
"Application": "Common feature in WebApi demo"
}
},
I even tried to delete the outputTemplate field but it always writes as
2019-06-05 10:42:32.952 +01:00 [Fatal] {My data}
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Appsettings.json based on environments doesn't load
Firstly you need to create launchSettings.json in Properties. enter image description here. With content some thing like this.
Read more >Application Settings (appsettings.json)
All of the application's settings are contained in a file named appsettings. json. Any changes to the appsettings. json file will require ...
Read more >Customized JSON formatting with Serilog
Log event levels, messages, stack traces and other properties introduce ... This post collects all kinds of JSON formatting examples using ...
Read more >The settings from the appsettings.json file
In this article, we will explain what settings are available in this file, what they are used for, and how to use these...
Read more >Cloud Explorer corrupts JSON formatting
Hi,. Today I was using cloud explorer to make a quick change to appsettings.json on a UAT version of a deployed web app...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi Pedro,
The problem here is that
outputTemplate
andformatter
are mutually-exclusive: only one or the other should be specified. Currently, when the configuration is ambiguous, the library will just choose one itself, which isoutputTemplate
in this case.Removing the
outputTemplate
option will get this working.HTH!
Hi @PedroS11 ,
Just checked with your config, it works. If you still hit the issue, try to update to the latest versions of the packages. If it doesn’t help, please re-open issue. Thanks