Logging with dotnet

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.

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

JAVA 8 — Lambda Function

App Academy W4D4

Fluent Builders in Automated Tests

Why You Should Always Implement TDD

Nice DP videos from Errichto

How to build a chatbot that reads all your website data to find the right answer

A brick layer’s introduction to Type Theory.

First Sinatra App

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Thejas`Gowda

Thejas`Gowda

More from Medium

Building a Cross Platform NuGet Package

Unit Tests a .NET 6 project with Azure Pipelines DotNetCoreCLI@2

GitHub Gist focus image

Uploading Large Size Files By Using Azure Blob Storage

.Net Core Tee Streaming and Buffered S3 Uploads