Summary
In this chapter, we delved into the concept of logging. We learned that logging is the practice of recording messages into a log for later use, such as debugging errors, tracing operations, and analyzing usage.
Logging is essential, and ASP.NET Core offers us various ways to log information independently of third-party libraries while allowing us to use our favorite logging framework. We can customize the way the logs are written and categorized. We can use zero or more logging providers. We can also create custom logging providers like AssertableLoggerProvider
and XunitTestOutputLoggerProvider
, which we used to experiment with the ASP.NET Core logging system (not depicted in the chapter, but available on GitHub). Finally, we can use configurations or code to filter logs and much more.
Here is the default logging pattern to remember:
- Inject an
ILogger<T>
, whereT
is the type of the class into which the logger is injected.T
becomes the category.
...