Skip to content

The logger specified through the options is not the one actually used to log requests #324

Open
@ydie22

Description

@ydie22

Description
When specifying a logger through the Logger property of the options, it appears that this logger is not the one that will be used to log requests.

Reproduction
app.UseSerilogRequestLogging(options => { options.Logger = myLogger; });
Expected behavior
I expect that the middleware will directly use the logger instance provided through the options. However, it appears that the middleware calls a ForContext() on that logger to obtain the logger it will use. Therefore, the configuration of the provided logger is ignored, as it is not used.

Relevant package, tooling and runtime versions
.NET 6, Serilog.AspNetCore 6.1.0

Additional context
I was expecting to be able to use a logger for a context controlled outside of the middleware, as we are logging requests (for other protocols than HTTP) at other places in our apps and therefore have more general configuration than just the Serilog middleware context.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions