Here is what I have in app.config
of my .NET 4.8 console application:
<add key="serilog:minimum-level" value="Information" />
<add key="serilog:using:File" value="Serilog.Sinks.File" />
<add key="serilog:using:Console" value="Serilog.Sinks.Console" />
<add key="serilog:write-to:File.path" value="MyAppLog.txt" />
<add key="serilog:write-to:File.rollingInterval" value="Day" />
<add key="serilog:write-to:File.formatter" value="Serilog.Formatting.Json.JsonFormatter, Serilog" />
This is how I initialize it in my code:
Log.Logger = new LoggerConfiguration().ReadFrom.AppSettings().CreateLogger();
I do have a reference to Serilog.Sinks.Console
added to my project.
It logs to text file as expected but nothing is output to console.
What do I need to change to get Serilog console output to work?
You're missing a key line in App.config
that actually enables console output.
To fix it, simply add this line to your <appSettings>
:
<add key="serilog:write-to:Console" />
This tells Serilog to use the Console sink that you already loaded via serilog:using:Console