serilog-settings-appsettings
serilog-settings-appsettings copied to clipboard
.ReadFrom.AppSettings(prefix) silently ignores missing settings
When using the AppSettings(prefix) overload, Serilog neither fails nor complains in the SelfLog about not finding any appSettings with that prefix.
How to reproduce
Create a project with no serilog related settings in web.config/app.config.
Setup SelfLog:
Serilog.Debugging.SelfLog.Enable(Console.Error); // Or some other destination of choice
Create a logger with any prefix:
var logger = new LoggerConfiguration()
.ReadFrom.AppSettings("MyLoggerA")
.CreateLogger();
logger.Information("Some log message");
Notice there's nothing written to Console.Error.
I can't figure out if that's by design or not, but it seems unintuitive, that this should silently go through without at least a warning in SelfLog.
If I instead add settings like:
<add key="MyLoggerA:serilog:using:File" value="Serilog.Sinks.File" />
<add key="MyLoggerA:serilog:write-to:File.path" value="Q:\Logs\Foged\Server\ApplicationLog.txt" />
It complains in SelfLog as I don't have a Q: drive.
Hi! This is by design - the absence of any settings for Serilog just means that there's no settings to apply.
It's quite a common pattern to configure baseline sinks etc. in code, but to add additional sinks in some environments via configuration files.
In the environments with no additional sinks, nothing goes into the config file. Because of this I don't think we'd emit a warning here.