Skip to content

dotnet-labs/UnitTestingWithILogger

Repository files navigation

Unit Testing with .NET Core ILogger<T>

Buy Me a Coffee at ko-fi.com

Because ILogger<T> objects are frequently used in controllers and service classes, we cannot avoid them in unit tests. In this post, we will go over some common ways to work with ILogger<T> objects in unit testing.

  1. Replace ILogger<T> with NullLogger<T>
  2. Create a Real ILogger<T> that Logs to Console
  3. Mock an ILogger<T> Object

License

Feel free to use the code in this repository as it is under MIT license.

Buy Me a Coffee at ko-fi.com