Closed
Description
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
Labels
No labels