Disable or change log level of: "No correlation ID was found in the request headers"
Giovyx opened this issue · comments
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
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();
}
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