Leveraging the logging framework
The logging framework, as mentioned at the beginning of the chapter, already has by design a series of providers that do not require adding any additional packages. Now, let us explore how to work with these providers and how to build custom ones. We will analyze only the Console log provider because it has all the sufficient elements to replicate the same reasoning on other log providers.
Console log
The Console
log provider is the most used one because, during the development, it gives us a lot of information and collects all the application errors.
Since .NET 6, this provider has been joined by the AddJsonConsole
provider, which, besides tracing the errors like the console, serializes them in a JSON object readable by the human eye.
In the following example, we show how to configure the JsonConsole
provider and also add indentation when writing the JSON payload:
builder.Logging.AddJsonConsole(options => Â Â Â Â ...