Logging with dotnet

Thejas`Gowda
2 min readSep 16, 2021

Logging Framework vs. Logging API: How We Use Both

When someone asks, “What Logger should I use for my application?” they are asking two questions:

  1. What is the logging API you want your code to utilize to capture log data?
  2. What is the logging framework you want to have implement that API to construct the formatted output various logs you want to record?

The API is what your code actually calls.

The framework is what creates the structured log messages with the data passed through the API.

Finally, the log messages are pushed to a sink, the mechanism used to store (and sometimes transport) the log data to where you can view it..

Microsoft.Extensions.Logging

It was introduced in .NET Core as a logging framework to be used across the entirety of .NET. It was kept for .NET 5 as the built-in logging framework for ASP.NET, Entity Framework, and even NuGet packages and other libraries.

So, for any developer that needs .NET 5 logging, it’s worth a look. It’s the default for the .NET ecosystem and should be for some time. But for developers putting in the effort to keep their logging architecture clean, there are two features that really make it shine:

  • Customizable logging providers to allow for different outputs without using multiple frameworks.
  • Logging scopes to add context to log messages cleanly and easily.

--

--