Skip to content

RequestLoggingMiddleware always logs requests to health check endpoint #332

@cremor

Description

@cremor

Description
The readme states the following for the UseSerilogRequestLogging() method:

The middleware will not time or log components that appear before it in the pipeline.

This seems to be not true for health check endpoints (HealthCheckMiddleware). Requests to those are always logged (and therefore cause log spam).

Reproduction
Add the following to a ASP.NET Core 7 project that uses Serilog:

builder.Services.AddHealthChecks();
[...]
app.MapHealthChecks("/healthz");
app.UseSerilogRequestLogging();

Expected behavior
Since MapHealthChecks() is called before UseSerilogRequestLogging() I do not expect to see any log lines from RequestLoggingMiddleware for calls to the health check endpoint.

Relevant package, tooling and runtime versions
Serilog.AspNetCore 7.0.0 on .NET 7

Additional context
There are ways to disable the health check request logging manually, as described in #121 (comment). But I think it should either work as documented by default, or at least mention this case (including solutions) in the readme.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions