GetRequiredService throw "The logger is already frozen"
See original GitHub issueDescription
in the project using Swashbuckle.AspNetCore, I try to use CreateBootstrapLogger to build a logger for Web API, but it cannot startup and throw the exception The logger is already frozen.
Reproduction


Expected behavior Expected not throw exception
Relevant package, tooling and runtime versions
netcoreapp3.1
Serilog.AspNetCore 4.1.0
Swashbuckle.AspNetCore 6.1.4
Additional context no
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Serilog logger freezes on every endpoint call
An unhandled exception has occurred while executing the request. System.InvalidOperationException: The logger is already frozen. at Serilog.
Read more >Supporting integration tests with WebApplicationFactory in ...
This will block the test code until one of three things happen: The web application throws an exception, which invokes the EntryPointCompleted() ...
Read more >What's new in .NET 8
MakeReadOnly() gives you explicit control over when a JsonSerializerOptions instance is frozen. (You can also check it with the IsReadOnly ...
Read more >NET 6 Web API with SQLite Database - Sean Spaniel
We need to write a unit test that verifies UserManager will actually log any exception thrown by IUserRepository. For this test, we'll need...
Read more >C# (CSharp) ServiceEndpoint Examples
MinimumRequiredOpenIdVersion) { throw new OpenIdException(string.Format(CultureInfo. ... null) { if (!Args.ContainsKey(Protocol.openidnp.ns)) { Logger.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I know this is an older issue but passing
preserveStaticLogger: trueto.UseSerilog(..)solved the issue for me. I have not found a way to get rid of myBuildServiceProvider()call, so this seems to be a way around theSystem.InvalidOperationException: The logger is already frozenHi @benlinx1018 ,
Building
IServiceProviderfrom theIServiceCollectionis not a recommended pattern because it can result in multiple constructions and undesired side effects. Use this one instead