In this video we will discuss the significance of LogLevel configuration in ASP.NET Core.
Text version of the video
https://csharp-video-tutorials.blogsp...
Slides
https://csharp-video-tutorials.blogsp...
ASP.NET Core Text Articles & Slides
https://csharp-video-tutorials.blogsp...
ASP.NET Core Tutorial
https://www.youtube.com/playlist?list...
Angular, JavaScript, jQuery, Dot Net & SQL Playlists
https://www.youtube.com/user/kudvenka...
LogLevel indicates the severity of the logged message. It can be any of the following. They are listed here from lowest to highest severity.
Trace = 0
Debug = 1
Information = 2
Warning = 3
Error = 4
Critical = 5
None = 6
LogLevel Enum
LogLevel enum is present in Microsoft.Extensions.Logging namespace
namespace Microsoft.Extensions.Logging
{ public enum LogLevel { Trace = 0, Debug = 1, Information = 2, Warning = 3, Error = 4, Critical = 5, None = 6 }
}
LogLevel in appsettings.json
LogLevel setting in appsettings.json file is used to control how much log data is logged or displayed.
"Logging": {
"LogLevel": { "Default": "Trace", "Microsoft": "Warning"
}
}
ILogger Methods
On the ILogger interface, we have log methods that include the log level in the method name. For example to log a TRACE message we use LogTrace() method. Similarly to log a WARNING message we use LogWarning() method. Notice, except for LogLevel = None, we have a corresponding method for every log level.
LogTrace()
LogDebug()
LogInformation()
LogWarning()
LogError()
LogCritical()
LogLevel Example
Consider the following Details() action in HomeController
public class HomeController : Controller
{ public ViewResult Details(int? id) { logger.LogTrace("Trace Log"); logger.LogDebug("Debug Log"); logger.LogInformation("Information Log"); logger.LogWarning("Warning Log"); logger.LogError("Error Log"); logger.LogCritical("Critical Log"); // Rest of the code }
}
The following is the LogLevl configuration in appsettings.json file.
"Logging": {
"LogLevel": { "Default": "Trace", "Microsoft": "Warning"
}
}
The following Log output is displayed in the Debug Output window. Since we have set "Default": "Trace", we see everything from Trace level and higher. Since Trace is the lowest level we see all the logs.
EmployeeManagement.Controllers.HomeController:Trace: Trace Log
EmployeeManagement.Controllers.HomeController:Debug: Debug Log
EmployeeManagement.Controllers.HomeController:Information: Information Log
EmployeeManagement.Controllers.HomeController:Warning: Warning Log
EmployeeManagement.Controllers.HomeController:Error: Error Log
EmployeeManagement.Controllers.HomeController:Critical: Critical Log
However if you want WARNING and higher then set "Default": "Warning"
If you do not want anything logged set LogLevel to None. The integer value of LogLevel.None is 6, which is higher than all the other log levels. So nothing gets logged.
Log filtering in ASP.NET Core
Consider the following log statement
EmployeeManagement.Controllers.HomeController:Trace: My log message
EmployeeManagement.Controllers.HomeController is the LOG CATEGORY
Trace is the LOG LEVEL. Remeber log level can be (Trace, Debug, Information, etc...)
In simple terms, LOG CATEGORY is the fully qualified name of the class that logged the message. The log category is displayed as a string in the logged message so we can use it easily determine from which class the log came from. LOG CATEGORY is used to filter logs.
asp.net core docker ASP NET Core LogLevel configuration | |
| 130 Likes | 130 Dislikes |
| 8,258 views views | 524K followers |
| Science & Technology | Upload TimePublished on 31 May 2019 |
Related keywords
tutorialspoint,webkinz,tutorials dojo,central park 5,webadvisor,asp.net core github,craigslist nj,asp.net core 3,server status,server jobs nyc,asp.net core swagger,weber grill parts,credit karma,services group,webtoon,tutorials by hugo,server error in '/' application,servers for minecraft,asp.net core dependency injection,services windows,asp.net core 3.0,tutorialspoint c#,services angular,calculator,tutorialspoint tableau,services google play apk,asp.net core 3 release date,server job description,tutorials by a,servicenow,webcam,webmd symptom,tutorialspoint python,services briefcase,asp.net core web api,craigslist ny,server pro,server status ffxiv,webcrims,cheap flights,server memes,asp.net core hosting,services sas,services online,chase,tutorialspoint java,serverless architecture,tutorialspoint java compiler,server resume,server books,tutorialspoint javascript,webmd,services technologies gps,college football,server jobs,cvs,website,cnn,website builder,costco hours,tutorialspoint sql,server side rendering,weber grills,tutorialspoint spring,serverless,tutorialspoint spark,asp.net core download,cool math games,webster bank,services & training hse colombia sas,servicestack,citibank,asp.net core identity,webstaurant,asp.net core logging,tutorialsystems,cunyfirst,services fms publish announcement,services.msc no abre,asp.net core razor pages,server duties,asp.net core environment variables,tutorials near me,server 2019,web of dreams,chernobyl,century 21,serverminer,webassign,services consultores,services consulting,services.msc,asp.net core configuration,asp.net core tutorial,asp.net core mvc,server hosting,chase online,costco,server jobs near me,webex,capital one,server rack,tutorialspoint html,craigslist,tutorialsteacher,webroot,tutorialspoint reactjs,asp.net core 2.2,services desk,tutorialspoint python 3,webster,services transmission company sas,asp.net core signalr,services manager,tutorialspoint spring boot,asp.net core middleware,services tag dell,web store,webmail,
Không có nhận xét nào:
Đăng nhận xét