serilog-settings-configuration icon indicating copy to clipboard operation
serilog-settings-configuration copied to clipboard

Configuration errors are ignored

Open leastprivilege opened this issue 5 years ago • 7 comments

My config file references a sink that is not included in my project - I would have expected that the call to ReadFrom.Configuration throws some sort of error - but it is silently ignored and the sink is just not added.

I would prefer an error - can I change this behavior somehow?

leastprivilege avatar Nov 02 '18 12:11 leastprivilege

Hi Dominick,

You are right, while it is very clear that we don't want "log events emitting" to crash apps, this policy should be a bit relaxed while reading configuration were throwing could help diagnose an issue. There is more in this wiki article : https://github.com/serilog/serilog/wiki/Reliability

There is no "flag" to change that behavior. You may find something in the SelfLog, though , see https://github.com/serilog/serilog/wiki/Debugging-and-Diagnostics.

Would something along the lines of what is described here help ?

tsimbalar avatar Nov 02 '18 13:11 tsimbalar

I'll have a look. Thanks!

leastprivilege avatar Nov 03 '18 08:11 leastprivilege

I see this is over two years old, but what is the current settings for this?

If people add sinks that are not included in the project (as per the OP) or indeed mistype ("Using": ["Serilog.Sinks.Seqq"] for example, if you are relying on people typing you have to expect mistakes). If you have two sinks, one is valid and one not the logger does not get created that means no logs are sent to the valid sink. So if you are logging Fatal in program.cs Main() the log will not get sent.

Is there anyway to get around this?

deathchurch avatar May 28 '20 15:05 deathchurch

Bumping this up, because I think this is very counter intuitive. While logging events should not fail, the configuration of the logger itself is a fundamental part of any application and failure to load the configured sinks really ought to be fatal.

It took me a bit to realize I forgot to include the Sinks.Console and Sinks.File packages when the logging was not working.

The whole point of logging is to avoid silent failures, so this is rather ironic.

gandhis1 avatar Feb 02 '21 14:02 gandhis1

Missing configuration (e.g. appsettings.json does not exist) results in a similar situation. It's especially surprising when combined with CreateBootstrapLogger() as demonstrated on https://nblumhardt.com/2020/10/bootstrap-logger/, where the application fails to start correctly and the Log.Fatal(...) call is nowhere to be seen since there are no loggers configured any more.

.NET 6 comes with GetRequiredSection that this library could incorporate, but that does not help in case of invalid configuration.

stijnherreman avatar Nov 23 '21 16:11 stijnherreman

I just got bit by this behavior too and also think that defaulting to silent failures is not ideal. I was able to diagnose this issue by enabling SelfLog.

SelfLog.Enable(text => Console.WriteLine("⚠️ Serilog internal error: " + text));

This printed the following diagnostic messages on the console.

⚠️ Serilog internal error: 2022-03-25T19:46:53.9965747Z Unable to find a method called ByExcluding. Candidate methods are:
Serilog.LoggerConfiguration With(Serilog.Configuration.LoggerFilterConfiguration, Serilog.Core.ILogEventFilter)
⚠️ Serilog internal error: 2022-03-25T19:46:53.9990917Z Unable to find a method called Console. Candidate methods are:
Serilog.LoggerConfiguration Sink(Serilog.Configuration.LoggerSinkConfiguration, Serilog.Core.ILogEventSink, Serilog.Events.LogEventLevel, Serilog.Core.LoggingLevelSwitch)
Serilog.LoggerConfiguration Logger(Serilog.Configuration.LoggerSinkConfiguration, System.Action`1[Serilog.LoggerConfiguration], Serilog.Events.LogEventLevel, Serilog.Core.LoggingLevelSwitch)
⚠️ Serilog internal error: 2022-03-25T19:46:54.0009874Z Unable to find a method called File. Candidate methods are:
Serilog.LoggerConfiguration Sink(Serilog.Configuration.LoggerSinkConfiguration, Serilog.Core.ILogEventSink, Serilog.Events.LogEventLevel, Serilog.Core.LoggingLevelSwitch)
Serilog.LoggerConfiguration Logger(Serilog.Configuration.LoggerSinkConfiguration, System.Action`1[Serilog.LoggerConfiguration], Serilog.Events.LogEventLevel, Serilog.Core.LoggingLevelSwitch)
⚠️ Serilog internal error: 2022-03-25T19:46:54.0025792Z Unable to find a method called File. Candidate methods are:
Serilog.LoggerConfiguration Sink(Serilog.Configuration.LoggerSinkConfiguration, Serilog.Core.ILogEventSink, Serilog.Events.LogEventLevel, Serilog.Core.LoggingLevelSwitch)
Serilog.LoggerConfiguration Logger(Serilog.Configuration.LoggerSinkConfiguration, System.Action`1[Serilog.LoggerConfiguration], Serilog.Events.LogEventLevel, Serilog.Core.LoggingLevelSwitch)
⚠️ Serilog internal error: 2022-03-25T19:46:54.0069407Z Unable to find a method called Udp. Candidate methods are:
Serilog.LoggerConfiguration Sink(Serilog.Configuration.LoggerSinkConfiguration, Serilog.Core.ILogEventSink, Serilog.Events.LogEventLevel, Serilog.Core.LoggingLevelSwitch)
Serilog.LoggerConfiguration Logger(Serilog.Configuration.LoggerSinkConfiguration, System.Action`1[Serilog.LoggerConfiguration], Serilog.Events.LogEventLevel, Serilog.Core.LoggingLevelSwitch)

The root cause of the issue was that I published a single exe. It is documented to workaround by explicitly adding a Serilog:Using section but is too easy to miss.

0xced avatar Mar 25 '22 19:03 0xced

Could be closed? Configuration errors are not ignored entirely. They are swallowed by default by design and SelfLog is a way to debug all issues with config.

sungam3r avatar Mar 13 '23 08:03 sungam3r