/TestingUtils.Logging

Methods and types supporting the use of Microsoft.Extensions.Logging.Abstractions, e.g., ILogger and ILogger<>, within unit and integration tests.

Primary LanguageC#MIT LicenseMIT

TestingUtils.Logging (NuGet)

Methods and types supporting the use of Microsoft.Extensions.Logging.Abstractions (e.g., ILogger and ILogger<>) within unit and integration tests.

Usage Examples

"Service" using ILogger<>

In this example, an application "service" performs logging of its internal work. It requires an ILogger<> in its constructor.

Note that the term "service" here is intentionally loose. It is intended only to be a type which performs a unit of work or presents a required interface.

In a production implementation, a similar type might have I/O dependencies (e.g., an Entity Framework DbContext, or an HttpClient). Alternately, they may require logging because they perform logic or handle requests which must be captured, e.g., for triage or compliance.

When identifying if this pattern fits a use case, common applicable type name suffixes: *Service, *Repository, *Handler

This example is centered around capturing logged messages which occur during unit testing.

ASP.NET Core API Controller using ILogger<>

In this example, an ASP.NET Core API Controller performs logging of its request processing. This example builds upon the service example, above.

This example is centered around capturing logged messages which occur during ASP.NET Core integration testing.