Skip to content

Causes application crash when used with Serilog bootstrap logger. #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Dimi1010 opened this issue Jul 3, 2022 · 2 comments
Closed

Comments

@Dimi1010
Copy link

Dimi1010 commented Jul 3, 2022

Description:

When trying to implement a two-state logger initialization with Serilog the application builder throws the following exception on build.

System.InvalidOperationException: The logger is already frozen.

The exception is not thrown when builder.Services.GenericServicesSimpleSetup<>() is not called.
The issue appears to be linked to the DI container being built twice, once in the GenericServices Setup and then in builder.Build().
In the first occasion EF Core obtains a logger from the service collection triggering Serilog.
The issue also appears similar to another issue on JADNC.

Potential workarounds:

As mentioned in the abovementioned issue, using a null logger factory can suppress the issue at the cost of disabling logging for EF Core.

builder.Services.AddDbContext<ApplicationBuilder>(options =>
{
    options.UseLoggerFactory(NullLoggerFactory.Instance);
})

Steps to reproduce:

Created a project repo where the issue can be explored: https://github.com/Dimi1010/EfCoreGenericServicesAndSerilogBootstrapRepo.
Run the project for reproduction.

Expected Behavior:

Exception should not be thrown and the app should start normally.

Actual Behavior:

Exception is thrown.

Versions Used:

  • EfCore.GenericServices version 5.1.1
  • ASP.NET Core version 6.0.2
  • Entity Framework Core version 6.0.6
  • Database provider: In memory
  • Serilog.AspNetCore version 5.0.0
@Dimi1010 Dimi1010 changed the title Can't be used with Serilog bootstrap logger. Causes application crash when used with Serilog bootstrap logger. Jul 3, 2022
@JonPSmith
Copy link
Owner

Hi @Dimi1010,

The change you want me to do isn't trivial and isn't a lot of people asking for this feature. I have others things to do so I'm not going to add this.

If you can work a way to add your feature works without breaking the current way it works I will look at it. Alternatively you can clone the code and create your own version.

@Dimi1010
Copy link
Author

Dimi1010 commented Jul 4, 2022

Alright, understandable. Closing this issue, but will leave it for the workaround if other people encounter similar problem.

@Dimi1010 Dimi1010 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants