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

Disable or change log level of: "No correlation ID was found in the request headers" #103

Open
Giovyx opened this issue Apr 16, 2021 · 2 comments

Comments

@Giovyx
Copy link

Giovyx commented Apr 16, 2021

Hello,
I would like to disable or better change the log level of the _missingCorrelationIdHeader log to Debug rather than Information, since not are requests are required to have such header in my application.

INFO - CorrelationId.CorrelationIdMiddleware: "No correlation ID was found in the request headers"

Is there a way to achieve such thing?
Or maybe consider adding it if not?

Regards

@nj-git
Copy link

nj-git commented May 22, 2021

I disabled it for Serilog using following command

public static Logger CreateLogger()
    {
        var configuration = LoadAppConfiguration();
        return new LoggerConfiguration()
            .ReadFrom.Configuration(configuration)
            .MinimumLevel.Override("CorrelationId", LogEventLevel.Error)
            .CreateLogger();
    }

@freerider75
Copy link

Although I think that it would be handy to have a configuration option to either suppress this message or to choose which loglevel to use for it, I managed to mute it with a log filter in the ConfigureLogging call:

.ConfigureLogging(builder =>
    {
        // ... other configs ...  
        builder.AddFilter((category, level) =>
            !(category.Contains(nameof(CorrelationIdMiddleware), StringComparison.InvariantCultureIgnoreCase) && level < LogLevel.Error));
    }

With nameof I try to prevent regressions in case the source code changed (I know, it's weak...) and with the (adjustable) level filter I'm not excluding important logs.

cheers

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

No branches or pull requests

3 participants