Adding log messages
To see what’s going on successfully or not when running the solution, we add log messages. The important parts of understanding the concept of logging are the following:
- The source: Who writes log information – what is the category name?
- The log provider: Where is log information written to?
- The log level: What is the level of the log message? Is it just information or an error?
- Filtering: What information is logged?
The source is defined using the ILogger<T>
generic interface. With this generic interface, the category name is taken from the class name of the generic parameter type. In case you use the ILoggerFactory
interface instead of ILogger<T>
, the category name is passed by invoking the CreateLogger
method. Examples of category names used by .NET are Microsoft.EntityFrameworkCore.Database.Command
, System.Net.Http.HttpClient
, and Microsoft.Hosting.Lifetime
. Having hierarchical names helps with common configuration...