How to Use and Unit Test ILogger
ILogger is at the heart of the ASP.NET Core infrastructure and works well when you use it correctly. If you approach it the wrong way, it is easy to go down a rabbit hole and burn lots of time trying to implement basic functionality. Follow these tips instead. This article gives you the basics on how to use and verify mocked calls without having to implement a class yourself. Here are some pointers in case you’ve been doing it wrong. Read on to understand the justification for these tips. Only use ILogger or ILoggerFactory in your implementations. Avoid making direct API calls to the logging library Use an off-the-shelf library. Don’t create a class that implements ILogger unless you explicitly want to build your own logging infrastructure. Choose the library based on the logging infrastructure you choose to use. You...