Skip to content
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

.ReadFrom.AppSettings(prefix) silently ignores missing settings #54

Open
Xerillio opened this issue Aug 2, 2024 · 1 comment
Open
Labels

Comments

@Xerillio
Copy link

Xerillio commented Aug 2, 2024

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.

@nblumhardt
Copy link
Member

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.

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

No branches or pull requests

2 participants