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

Changing the Override in appsettings.json has no effect when app is running? #328

Closed
No0Vad opened this issue May 8, 2023 · 3 comments
Closed
Labels

Comments

@No0Vad
Copy link

No0Vad commented May 8, 2023

Description
Changing values to "Override" property in the appsettings.json during runtime has no effect.

Reproduction
Sample appsettings.json

{
    "Serilog":
    {
        "MinimumLevel":
        {
            "Default": "Information",
            "Override":
            {
                "Microsoft": "Warning",
                "Microsoft.Hosting.Lifetime": "Information",
                "System.Net.Http.HttpClient": "Warning"
            }
        }
    },

    "AllowedHosts": "*"
}

Sample program.cs code bits

var builder = WebApplication.CreateBuilder(args);

builder.Host.UseSerilog((context, services, configuration) => configuration
    .ReadFrom.Configuration(context.Configuration)
    .Enrich.FromLogContext()
    .WriteTo.Console(outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u4}] ({SourceContext}->{Method}) {Message}{NewLine}{Exception}")
);

Now if I change the appsettings.json to this and save the file, nothing is changed. I expect a lot more the be seen in the log when I visit a controller.

{
    "Serilog":
    {
        "MinimumLevel":
        {
            "Default": "Information",
            "Override":
            {
                "Microsoft": "Verbose",
                "Microsoft.Hosting.Lifetime": "Verbose",
                "System.Net.Http.HttpClient": "Verbose"
            }
        }
    },

    "AllowedHosts": "*"
}

Only when I restart the app my changes take effect.

Expected behavior
The overrides to change to the new values, and I should see a lot more log entries.

Relevant package, tooling and runtime versions
.NET 7
Serilog.AspNetCore v6.1.0
Serilog.Sinks.Seq v5.2.2

Additional context
Code samples are simple but it is used in a simple MVC app where ILogger is injected to the controller. Logs are also saved to Seq

@No0Vad No0Vad added the bug label May 8, 2023
@augustoproiete augustoproiete added invalid and removed bug labels May 8, 2023
@augustoproiete
Copy link
Member

This is by design. Serilog prefers an immutable logging pipeline that the application uses for the remainder of its execution time.

In order for updates to the configuration to reflect in the app, you'll need to recreate the Serilog pipeline... Some alternatives would be:

N.B.: The best way to get answers on usage of Serilog is to post a question on stackoverflow.com including the serilog tag and details of the code you are using and some context the kind of app you are building

https://stackoverflow.com/questions/tagged/serilog

@No0Vad
Copy link
Author

No0Vad commented May 8, 2023

Ah, I assumed it was a bug since it did not do what I expected to do when it comes to the appsettings.json file.

Thanks for the links! I'll give them a look!

@No0Vad No0Vad closed this as completed May 8, 2023
@sungam3r
Copy link
Contributor

sungam3r commented May 9, 2023

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

3 participants