'Using ILogger<T> without constructor injection
I have my registration and constructor setup to use logging via Microsoft.Extensions.Logging as follows,
public MyService(ILogger<MyService> logger) {}
What I'd like to do, though, is use services.AddSingleton() in my Startup.cs to avoid using constructor injection. The reason is that it will otherwise require modifying all unit tests to Mock the logger when testing the service.
I believe there's a way to register the specific instance of ILogger in the ServiceCollection, but I cannot sort out the syntax required.
Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
