Skip to content

Middleware relies on static Log.Logger being set first. #182

Closed
@dazinator

Description

@dazinator

I am trying to use only instances of ILogger. As such I wondered what would happen if I never set Log.Logger.

I found was now getting no request logging. Looking at the request logging middleware it looks like Log.Logger needs to be set first as it uses Log.ForContext: https://github.com/serilog/serilog-aspnetcore/blob/dev/src/Serilog.AspNetCore/AspNetCore/RequestLoggingMiddleware.cs#L76 and if Log.Logger isn't set this yields SilentLogger's. (To be honest I would think it would be better to throw an exception in such a case as logging not being initialised is pretty important)

I'd propose an enhancement to the middleware so that an instance of a logger can be provided and that used to get log context instead --> falling back to the static Log.Logger if no instance provided might be a good way to keep this a backwards compatible change?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions