Adding logging to your application

Running applications in production can be very complex. A lot of things might happen when your application is in the wild, things that you don't expect, or that slipped your QA process, such as edge cases or events in the data center that affect your application. Besides these cases, there are times when you want to investigate the correct flow of work and get insights about how a certain feature is used, or if it is used at all. Your best friend in the aforementioned cases is the log. Logging in ASP.NET Core is now a first-class citizen, and a logging framework, middleware, and abstraction layer are included out-of-the-box, so it's much easier to work with different logging packages and providers. 

The Microsoft.Extensions.Logging package, which is referenced by the Microsoft.AspNetCore.App meta-package, contains the building blocks of the logging infrastructure. The following list explains what the main classes are in the logging infrastructure: 

  • ILogger and ILogger<T>: These are abstractions for the type used to perform the logging. The generic parameter is meant to be the type by which the logger is used—this type will be the category name of the log events.
  • ILoggerProvider: This is an abstraction for a type that can create instances of ILogger for a specific target (such as a file or console window). There can be more than one provider in your application. 
  • ILoggerFactory: This is an abstraction for the type, used to configure the logging and create instances of ILogger from a given ILoggerProvider.

By using these building block types, you can write log events that describe different scenarios that happen in your application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.144.194