Basics of Logging in ASP.NET Core
One of ASP.NET Core's features is its in-built logging using ILoggerFactory
. Right away, when you create an ASP.NET Core application (empty-, MVC-, or web API-based), you will see that the IWebHost's CreateDefaultBuilder
method of the program class does the ground-level work for the Logging functionality to work-it reads the appsettings.json
file for the logging section to provide all the necessary infrastructure to log information to debug or console window.
The use of Logging is greatly simplified by ILoggerFactory
in two parts--AddProvider
and CreateLogger
.
The AddProvider
method takes in ILoggerProvider
to write/store the logging information generated by the application. The provider can either be a console, debug window, file, database, cloud-based storage, or third-party log analysis service (Splunk, Raygun, Loggly, and so on).
The CreateLogger
method takes the name of the class or method that will write the log information through the aforementioned...