Skip to content

RollingFile + JsonFormatter from config = plain text logs #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andersnm opened this issue Mar 14, 2017 · 2 comments
Closed

RollingFile + JsonFormatter from config = plain text logs #42

andersnm opened this issue Mar 14, 2017 · 2 comments

Comments

@andersnm
Copy link

Am unable to enable the JsonFormatter with RollingFile from a configuration file. Any insight would be appreciated, presumably I'm missing something obvious

Have updated all package versions, made sure to using "formatter" as the type parameter, and carefully pasted the typename per the only documentation I could find:
http://stackoverflow.com/questions/40880261/configuring-serilog-rollingfile-with-appsettings-json
#31

Have tried to delete all Serilog.* packages from my .nuget folder and refresh. Have tried both older/newer version of the serilog and configuration packages. Made no difference though.

project.json:
"Serilog": "2.3.0",
"Serilog.Extensions.Logging": "1.4.0",
"Serilog.Enrichers.Environment": "2.0.0",
"Serilog.Enrichers.Process": "2.0.0",
"Serilog.Enrichers.Thread": "2.0.0",
"Serilog.Sinks.RollingFile": "2.0.0",
"Serilog.Sinks.Seq": "2.0.0",
"Serilog.Sinks.ColoredConsole": "2.0.0",
"Serilog.Settings.Configuration": "2.2.0"

config.json:
"Serilog": {
"Using": [ "Serilog.Sinks.RollingFile" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "RollingFile",
"Args": {
"pathFormat": "c:\logs\application\log-{Date}.json",
"formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog",
"retainedFileCountLimit": "7"
}
}
],
"Enrich": [ "WithMachineName", "WithThreadId", "WithProcessId" ]
}

Unexpectedly this generates log files in plain text (altho in the expected location!). The JsonFormatter configuration is silently ignored:

2017-03-14 15:18:51.192 +01:00 [Debug] Hosting starting
2017-03-14 15:18:51.394 +01:00 [Debug] Hosting started
2017-03-14 15:18:51.627 +01:00 [Information] Request starting HTTP/1.1 GET http://localhost:49652/
etc

The app targets the full .NET framework 4.5.1

@skomis-mm
Copy link
Contributor

@andersnm , I think you need upgrade RollingFile package to at least version 2.1.0
see this

@andersnm
Copy link
Author

Obvious indeed, found my own problem after trying some random stuff

It works when updating the rolling file package:
"Serilog.Sinks.RollingFile": "2.2.0",

Also thanks @skomis-mm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants