Logging in ASP NET Core



Logging in ASP NET Core

Logging in ASP NET Core

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.blogspot.com/2019/05/logging-in-aspnet-core.html

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.
https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation=1

Slides
https://csharp-video-tutorials.blogspot.com/2019/05/logging-in-aspnet-core-slides.html

ASP.NET Core Text Articles & Slides
https://csharp-video-tutorials.blogspot.com/2019/01/aspnet-core-tutorial-for-beginners.html

ASP.NET Core Tutorial
https://www.youtube.com/playlist?list=PL6n9fhu94yhVkdrusLaQsfERmL_Jh4XmU

Angular, JavaScript, jQuery, Dot Net & SQL Playlists
https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd

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.

Comments are closed.