Skip to content

Can't use Serilog bootstrap logger with JADNC #1082

Closed
@LoremFooBar

Description

@LoremFooBar

DESCRIPTION

When trying to implement two-stage logger initialization with Serilog, an exception is thrown:

System.InvalidOperationException: The logger is already frozen.

Exception is not thrown when removing services.AddJsonApi() call. It seems this is happening because the callback to UseSerilog is invoked twice: once when building the ASP.NET host, and once when building an intermediate ServiceProvider in JsonApiApplicationBuilder ctor. as far as I understand, it is recommended to avoid building ServiceProvider during DI services registration.

STEPS TO REPRODUCE

I created a repro: https://github.com/lazyboy1/JsonApiSerilogBootstrapLoggerRepro. Run the project to see the exception.

EXPECTED BEHAVIOR

Exception should not be thrown, and app should start with both the recommended Serilog configuration and JADNC.

ACTUAL BEHAVIOR

Exception is thrown.

VERSIONS USED

  • JsonApiDotNetCore version: 4.2.0
  • ASP.NET Core version: 5.0
  • Entity Framework Core version: 5.0.10
  • Database provider: In memory

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