-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Open
Milestone
Description
I use: _logger = this.GetService<ILogger<MyContext>>(); inside the constructor of MyContext
The call to InfrastructureExtensions.GetService however throws an error in case there is no logger registered.
I wasn't expecting this as i assumed it would behave like the regular serviceprovider. getservice.
as compared with GetRequiredService that could throw an error.
Is there any possibility to get an instance of the logger without getting the error in case it's not configured?
(I know i can add a parameter to the constructor but that isn't an option for some reason.) or maybe update the InfrastructureExtensions to support both getservice and getrequiredservice?
As a workaround I now use: new Logger<MyContext>(this.GetService<ILoggerFactory>());
Reactions are currently unavailable