Logging in ASP NET Core
kudvenkat kudvenkat
835K subscribers
147,176 views
1K

 Published On May 28, 2019

In this video we will discuss Logging in ASP.NET Core.

Logging providers in ASP.NET Core

Text version of the video
https://csharp-video-tutorials.blogsp...

Healthy diet is very important for both body and mind. We want to inspire you to cook and eat healthy. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking.
   / @aarvikitchen5572  

Slides
https://csharp-video-tutorials.blogsp...

ASP.NET Core Text Articles & Slides
https://csharp-video-tutorials.blogsp...

ASP.NET Core Tutorial
   • ASP.NET core tutorial for beginners  

Angular, JavaScript, jQuery, Dot Net & SQL Playlists
https://www.youtube.com/user/kudvenka...


A logging provider is the component that stores or displays logs. For example, the Console log provider displays logs on the console. Similarly, the Debug log provider displays logs on the Debug window in Visual Studio.

ASP.NET Core built-in logging providers

Console
Debug
EventSource
EventLog
TraceSource
AzureAppServicesFile
AzureAppServicesBlob
ApplicationInsights

Third party logging providers for ASP.NET Core

NLog
elmah
Serilog
Sentry
Gelf
JSNLog
KissLog.net
Loggr
Stackdriver

Default logging providers in ASP.NET Core

Main() method in the Program class in Program.cs file is the entry point for an asp.net core application. This method calls CreateDefaultBuilder() method performs several tasks like
Setting up the web server
Loading the host and application configuration from various configuration sources and
Configuring logging

Since ASP.NET Core is open source we can see the complete source on their official github page. The following is the code snippet from CreateDefaultBuilder() method.

.ConfigureLogging((hostingContext, logging) =]
{
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
logging.AddConsole();
logging.AddDebug();
logging.AddEventSourceLogger();
})

As part of configuring logging, CreateDefaultBuilder() method adds the following 3 logging providers by default. This is the reason when we run the asp.net core project we see the log displayed both on the console and on the debug window in Visual Studio.
Console
Debug
EventSource

CreateDefaultBuilder() method looks for Logging section in the application configuration file appsettings.json.

Logging section in appsettings.json

The following is the Logging section in appsettings.json file on my machine.

"Logging": {
"LogLevel": {
"Default": "Warning",
"Microsoft": "Information"
}
}

LogLevel is used to control how much log data is logged or displayed. We will discuss Log level in detail in our upcoming videos.

show more

Share/Embed