Logging in ASP NET Core

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this is part 61 of asp.net core tutorial in this video I'll introduce logging capabilities in a spirited core before we write any logging code or configuration let's look at the default logging that we get out of the box with a speed on it core to understand that I'm going to run this project that we've been working with so far in this video series in debug mode by clicking this Run button there we go we have our application up and running now if we take a look at the output window within Visual Studio by the way if the output window is not present here for you to open this click on debug windows and then select output notice within the output window here we have a lot of information dumped by the process dotnet dot exe and if we scroll all the way down again we have lot of messages here related to thread has exited that code zero at the moment we are running our project using the out of process hosting model so if we take a look at our project file notice we are using out of process so the process that is dumping all this information here is dotnet dot exe if you have used in process hosting model then instead of dot dot exe you would see is Express dot exe dumping all this information right here to prevent all these messages being logged to the output window within Visual Studio we can click on Tools options and in this options window collapse the environment tab expand debugging and then select output window I'm going to turn off all these messages being logged to the output vendor click okay stop debugging and then let's run the project again in debug mode now if we take a look at the output window again notice we don't have anything logged here let me stop debugging again in our application configuration file that is in this app settings dot Jason I'm going to include another log level setting these log level settings are related to login configuration we'll discus log level in detail in our upcoming videos for now I'm going to include another category here Microsoft and said this - information log level with this setting in place we are basically saying all the information logs and higher that are coming from the Microsoft category must be logged and displayed well this is this log level configuration in detail in our upcoming videos for now less than our project in debug mode again and see the behavior that we get if we now take a look at the output window notice we have a lot of information logged the first part here that we see is the category of the log and notice it starts with the word Microsoft and this is an information log and the log message is request starting that's because we basically said we want all the information level logs and higher from the Microsoft category and we see several logs here including the Select query that is issued by Microsoft entry framework or to retrieve the list of employees that we see on this web page at the moment we are running this project from visual studio in debug mode and we see all these log messages displayed in the debug output window asp.net core is cross-platform and we can run this same project even from the command line so let's stop debugging that and visual studio and then launch command prompt as an administrator in the command prompt window changed the path to the folder that contains your project in my case the project is pleasant in sequel and projects folder this solution folder is employee management within that we have another folder with the same name employee management which is our project folder right here run the command dotnet run to run our dotnet project we have our application up and running and it's listening for incoming request at this URL localhost colon 5000 so in the browser address bar let's navigate to localhost 5000 there we go we have our list of employees now if we take a look at the console window notice we have a lot of information logged just like the debug window in Visual Studio the category name here starts with the bird Microsoft the log level is info and we also have the sequel query issued by entry framework or to retrieve the list of employees now the point that I'm trying to make is we did not write any code except this one line of configuration right here to have these logs displayed on the console window if we are running at a project from the command line and in the debug output window if we are running the project from Visual Studio in debug mode so how are these logs displayed well we have something called logging providers and these logging providers physically store or display logs for example we have console logging provider this provider displays logs on a console if we are running the project from the command line similarly we have debug login provider this provider displays logs on the debug window in Visual Studio if we are running the project in Visual Studio in debug mode now you know previous videos in the series we discussed the significance of the main method in this program dot C s file it is the entry point into our asp.net core application this method calls create web host builder which in turn calls create default builder this method several tasks while starting our asp.net core application it is this method that sets of the webserver loads our application configuration information from various configuration sources and it is also responsible for configuring logging at the moment we are on the official asp.net core github page using the search box that we have right here I have searched for this create default builder method in this repo and at the moment we are looking at web host dot CS file and if we scroll down notice we have the create default builder method right here and as you can see this method configures our application configuration and if we scroll down a bit further notice it also configures logging as part of this login configuration notice it's looking for logging related settings in a section called logging so if we take a look at app settings dot JSON file notice we have a section with named logging and inside that we have a nested log level object will discuss log levels in detail in our upcoming videos in addition to reading the logging related configuration information from logging section it also adds these three logging providers console debug and even source to our application out-of-the-box this is the reason we are able to see the logs displayed in the console window and in the debug output window in visual studio in addition to these three logging providers console debug and even servers there are several other built-in logging providers provided by asp.net core out of the box as we already discussed these different logging providers allow us to send logs to different destinations for example console displays logs on the console window if you have into operating system and you want to log the messages to the Windows Event log then use event log provider similarly as your app services file provider logs messages to the azure app services file and similarly this provider logs messages to as your app services blob storage in addition to these built-in login providers provided by asp.net core we also have several third-party login providers we have for example an log el-masri log etc in our upcoming videos in the series well discus how to log warnings and exceptions from our application to a file using this third-party logging provider n log this is just an introduction to logging capabilities in a spirited core there's a lot more to learn we will cover most of the login concepts in our upcoming videos in this series so please stay tuned thank you for listening [Music] you
Info
Channel: kudvenkat
Views: 141,032
Rating: undefined out of 5
Keywords: asp.net core logging tutorial, asp.net core mvc logging, asp.net core logging middleware, asp.net core logging providers, asp.net core logging example
Id: WyAJe6lA-bY
Channel Id: undefined
Length: 9min 27sec (567 seconds)
Published: Tue May 28 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.