Operations | Monitoring | ITSM | DevOps | Cloud

February 2024

Testing logging code with Microsoft.Extensions.Logging and FakeLogger

Unit testing is most often used for testing business logic. But what if you want to ensure that your code logs important messages to your log store? In this post, I'll introduce you to FakeLogger and how it can be used to test logging code when using Microsoft.Extensions.Logging and the ILogger interface. So, let's start by discussing why to even unit-test logging code. Adding good logging to your code is an often forgotten or down-prioritized practice.