fix: remove request to /health from log

This commit is contained in:
Polianin Nikita 2024-10-25 02:37:08 +03:00
parent 4fc28378c5
commit ebec0a2d2b

View File

@ -59,19 +59,25 @@ public static class LoggerConfiguration
{ {
options.MessageTemplate = "[{RequestMethod}] {RequestPath} [Client {RemoteIPAddress}] [{StatusCode}] in {Elapsed:0.0000} ms"; options.MessageTemplate = "[{RequestMethod}] {RequestPath} [Client {RemoteIPAddress}] [{StatusCode}] in {Elapsed:0.0000} ms";
options.GetLevel = (_, elapsed, ex) => elapsed >= 2500 || ex != null options.GetLevel = (httpContext, elapsed, ex) =>
? LogEventLevel.Warning {
: elapsed >= 1000 if (httpContext.Request.Path.StartsWithSegments("/health"))
? LogEventLevel.Information return LogEventLevel.Verbose;
: LogEventLevel.Debug;
return elapsed >= 2500 || ex != null
? LogEventLevel.Warning
: elapsed >= 1000
? LogEventLevel.Information
: LogEventLevel.Debug;
};
options.EnrichDiagnosticContext = (diagnosticContext, httpContext) => options.EnrichDiagnosticContext = (diagnosticContext, httpContext) =>
{ {
diagnosticContext.Set("RequestHost", httpContext.Request.Host.Value); diagnosticContext.Set("RequestHost", httpContext.Request.Host.Value);
diagnosticContext.Set("RequestScheme", httpContext.Request.Scheme); diagnosticContext.Set("RequestScheme", httpContext.Request.Scheme);
diagnosticContext.Set("UserAgent", httpContext.Request.Headers.UserAgent); diagnosticContext.Set("UserAgent", httpContext.Request.Headers.UserAgent);
diagnosticContext.Set("RemoteIPAddress", httpContext.Connection.RemoteIpAddress?.ToString()); diagnosticContext.Set("RemoteIPAddress", httpContext.Connection.RemoteIpAddress?.ToString());
}; };
}); });
} }
} }