Part 73. Logging in ASP. NET Core | Logging Providers | Use specific logging providers.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] foreign [Music] Concepts my name is Amit and this is part 73 of the asp.net code MVC tutorial in this video we will learn about the logging mechanism in asp.net core this is a continuation of part 72 use status code pages with redirects versus re-execute in asp.net curve so please watch it before proceeding to this one I shared the link in the description first let's understand a few basic concepts around login let's read the definition first login nasp.net core refers to the process of recording application events exception and information that can be useful for debugging troubleshooting and analyzing application Behavior when you heard the word login what is the first thought that comes to your mind for me it's a text file because in most of my live applications we store our logs in text file some of you might be thinking about databases like SQL MySQL Etc maybe because in your organization or in your college project you might have to store your logs in some databases right so these are the most common places where logs gets captured is this statement correct no what if I tell you for dotnet developers there is an even more common place where logging happens can you guess no worries if you can't think of it let me tell you these places are your debug and console don't believe me let's see that in action let's go to the visual studio and this is the project which we are working with we haven't implemented any kind of logging mechanism yet in our project let me just select Castrol as a server and to do that I have to select the pro Concepts profile from the top I am selecting it so that we will get the console window and let's just run our application in this console window you can see there are some information provided like the application is listening to this port use this shortcut to shut down the application environment and content root path and you can see all these are of type info logs information logs let's check the same Endeavor let's go to the output window if you don't see it here just go to debug windows and output or go to views and then output all right here you can see we have selected show output from debug and because we selected Castrol as a web server the message is from pro project name.exe which is proconcept.exe in our case if we select is Express messages will be provided by is Express all right here we get lots of other messages as compared to console it's because by default the module load messages are enabled let's disable that first let's stop the application and let's go to tools options debugging and output window and then off module load messages once it is done let's run your application once again and you can see we have this same messages and debug window as well that concludes logging is enabled by default in asp.net core let's go to slide again now if I ask you to write logs to text files and write logs to some database then you have to write separate code for both of them right similarly console and debug are separate things and the code or packages or new get package whatever you would like to say who owns the responsibility to lock somewhere called logging provider so if you have to provide logs in console you have to write code to display logs in console but the good news is Microsoft already writes the code and they call it console login provider so the console login provider locks output to the console for debug we have debug logging provider the debug logging provider writes logs output by using the system.tagnostic dot debug class calls to system.diagnostic.debug.wrightlines rights to the debug provider out of the box Microsoft provides support for two more sources Event Source and we have an even Source logging provider for this The Event Source provider writes to a cross-platform event sources with the name Microsoft extension plugin on Windows the provider uses etw and the last one event log and we have event log locking provider the event log provider sends logs output to the Windows Event log do not worry about these providers we will cover them in some other video the idea is there are lots of places where we can write these logs if I talk about the simplest one a text file these providers don't log in a text file so you have two options either write your own logic to write logs to a text file or use any other party logging provider simple extremely simple do not worry about anything we will cover everything in our upcoming videos first quickly let's find out which class has that code written I mean where the code is written to capture logs in these console Audible for application Level configuration the best places program class let's go to program.cs class and we have a method called create Builder let's go to Microsoft page here they specify call Window web application.createbuilder which adds the following logging provider console debug Event Source event lock Windows only so this particular line adds all these providers all right this is the GitHub page of the web host class which is internally called by web application.createbuilder method and here search for create default Builder method and here you can see this method is doing many things along with enabling default login providers first it tries to get a section called logging from our app settings file and based on that it enables these logging providers all right we'll cover these app setting related stuff later first let's see what if we don't want to use this logging Provider by default can we clear them and the answer is absolutely let's see that go to the program.cs class here we created a default Builder here logging is enabled let me chain it with another command Builder Dot Login dot clear providers now it will clear all the default logging providers let's run our application once again with Castrol as a web server here you can see application is started and there are no logs in console let's go to debug and you can see no locks in debugs window either now if you want to enable any default provider you can also do that let's stop the application let's say we only want to enable logs in console so type Builder dot logging dot add console and run our application once again and you can see now locks get captured in the console but in debug there are still no logs simple extremely simple let's quickly summarize logging in asp.net core refers to the process of recording application events exception and information that can be useful for debugging troubleshooting and analyzing application Behavior asp.net core includes a built-in logging framework that allows developer to log messages the default asp.net core configures the following logging providers console debug Event Source and event law on Windows we can override the default set of login providers by calling clear providers and adding the specific ones you need this is a very basic information about logging and we will cover logging in more detail in our upcoming videos so that's it from this video hope you like our content if you have any queries related to the content of this video do ask me in the comments till then thanks for watching foreign [Music] thank you
Info
Channel: PRO Concepts
Views: 719
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, asp.net core, asp.net core tutorial, dotnet core, asp.net mvc core tutorial, asp.net mvc core course, dot net core mvc tutorial, .net core tutorial, aspnetcore, pro concepts, amit
Id: WJnBLSwiOhg
Channel Id: undefined
Length: 9min 47sec (587 seconds)
Published: Wed Jun 07 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.