Verifying logging using Moq

Let's learn how to verify our implemented logging. The dependency injection system of the ILogger interface helps us to mock the logging mechanism and validate the resulting implementation. It is essential to note that our handlers are using the extension methods of the ILogger interface. Let's use the ASP.NET Core implementation of the LogInformation extension method in the Microsoft.Extensions.Logging namespace as an example:

using Microsoft.Extensions.Logging.Internal;using System;namespace Microsoft.Extensions.Logging{  /// <summary>ILogger extension methods for common scenarios.</summary>  public static class LoggerExtensions  {        public static void LogInformation(this ILogger logger,            Exception exception, string ...

Get Hands-On RESTful Web Services with ASP.NET Core 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.