serilog / serilog-settings-configuration

A Serilog configuration provider that reads from Microsoft.Extensions.Configuration
Apache License 2.0
446 stars 129 forks source link

Serilog seq configuration is not reloaded when Seq serverUri is updated in appsettings.json file #346

Closed bigswede74 closed 1 year ago

bigswede74 commented 1 year ago

Description

I have a windows application that is logging using the Serilog.Sinks.Seq. All the configuration is coming from the appsettings.json file however when I update the serverUri while the application is running the configuration is not dynamically reloaded until the application is restarted. Does the seq sink support dynamic configuration updates for the serverUri?

Reproduction

Program.cs


private ILogger _logger;
private IConfiguration _configuration; 

public static void Main(string[] args)
{
    var builder = new ConfigurationBuilder()
        .SetBasePath(Directory.GetCurrentDirectory())
        .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);

    _configuration = builder.Build();

    _logger = new LoggerConfiguration()
        .ReadFrom.Configuration(_configuration)
        .CreateLogger();

    Log.Logger = _logger;
}

appsettings.json

{
    "Serilog": {
        "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File", "Serilog.Sinks.Seq" ],
        "MinimumLevel": "Information",
        "WriteTo": [
            {
                "Name": "Console"
            },
            {
                "Name": "File",
                "Args": {
                    "path": "C:\\logs\\myApp-.log",
                    "fileSizeLimitBytes": 200000000,
                    "rollOnFileSizeLimit": true,
                    "rollingInterval": "Day",
                    "retainedFileCountLimit": 14
                }
            },
            {
                "Name": "Seq",
                "Args": {
                    "serverUrl": "http://localhost:5341"
                }
            }
        ],
        "Enrich": [ "FromLogContext", "FromGlobalLogContext" ],
        "Destructure": [
            {
                "Name": "ToMaximumDepth",
                "Args": {
                    "maximumDestructuringDepth": 20
                }
            }
        ],
        "Properties": {
            "ApplicationName": "MyApp"
        }
    }
}

Expected behavior Logs should be forwarded to the new seq address

Relevant package, tooling and runtime versions Packages

Platform

nblumhardt commented 1 year ago

Hi! AFAIK, Serilog.Settings.Configuration only supports reloading a small number of settings at runtime (minimum level being the one I know of). I don't think there's any support for reloading sink arguments like these. HTH!

bigswede74 commented 1 year ago

Thanks for the quick response. Any recommendations on how I can accomplish this would be welcome. Should I just re-initialize a new logger and replace it in the DI container?

SimonCropp commented 1 year ago

restart the app