Skip to main content

What is NLog ?



Nlog is .NET Library which enables to add some sophisticated traces code to your application and delivering the flow of diagnostic traces from source to target

What is source code?     
              
                   The source code is the fundamental component of a computer program that is created by a programmer and sequence formate.
                   We can control the flow of diagnostic traces from source to target type.

Types of Target:
  • Email Messages(.mail) 
  • Text File(.txt)
  • Event Log(.log)
  • Database(.db) and etc
These all are called as target type messages.Each trace messages augmented with some contextual information.

What is Contextual information?    
            
 Contextual information can include following below
  • Source name 
  • Thread name
  • Current Date and Time
  • Log level                      
These all information which will be sent with it to target type. Each tracing messages is associated with some log level.

Types of Log level:

There are six types of Log level is there
  • Trace (Will give very detailed log messages only)
  • Debug(Will give Fewer log messages only)
  • Info(Will give informational messages only)
  • Warn(Will give the warning which doesn't appear to the user interface)
  • Error(Will give error messages only)
  • Fatal(If this  log we get once an application will automatically be terminated)
How to install Nlog in visual studio?

                     By installing Nlog to your application only you can trace your code and get log messages. Now I will tell how to install.


Step1: Open Visual Studio and Select "Solution Explorer".


Step2:  Right click and Select Managers NuGet Packages.

Step3: Select Online and Type Search box "nlog".

Step4: Now you can see a lot of software related to nlog.

Please choose nlog and click install(You must also install Nlog configuration).

EXAMPLE:
                        

                
From above Picture, you can see Nlog.config that is installed in visual studio.net and two tags available a "target" and "rules" these all in nlog closed tags.Now I am going to explain what is this and how to work with this.
<targets>

     From this tag, you can see Name, xsi:type, Filename.
 Name: Whenever you're going to set target type, first of all, you have to give the name of the type.It can be any name here they chose name called file.

Xsi:type: From here you can give which target type you want(textfile, email messages, database, console anything you can choose here they chose target type called file).


Filename:${basedir}/log.txt

${}-Called layout renderers from here you have to create a folder and give that directory.
for example:fileName="C:\Test\txt.log"----Test is a folder name and txt.log is extension.
From this folder, the log messages will store.

</targets>

<rules>


    From this tag, you can see logger name, minlevel, WriteTo.
logger name: you can give namespace of your project or '*'.

MinlevelFrom here you can give log level(Trace, Debug, Info, Warn, Error, Fadal)here they chose Debug.


WriteToFrom this place, you have to give target name..If you target name is "file" then WriteTo should "file".we have to give the name depends upon target name.  


</rules>

Final one:


         For calling this method you have to make a call from the Main method. So we need to give codes
                       private static Logger logger = LogManager.GetCurrentClassLogger(); (give this code to before main method make this last).
                        logger.Trace(String.Format(""));(give this code after main method make this first)

Logger:
 In order to send a diagnostic message we use logger.

LogManager: Logger object can be created using log manager class.
GetCurretClassLogger: This method will automatically create a logger.

I will show my programme.



After all setup, you are log messages will be created in the specific folder that you are given in filename of your targets by running you the programme.

That's all you are done for creating Nlog to your project. Thank you hope this will help you lot.



Click To Know: What is Window Service?











Comments

Popular posts from this blog

What is System Software and Application Software?

In this section, we are going to discuss the difference between system software and application software. Still, most of us have a lot of confusion about these two. I will clarify let me explain What is Software? Software means a set of the program made to complete some task. Its full and full codes. What is hardware? Hardware is physical one that we can touch and feel and made with some electrical components and that have some specific functions. For example Monitor, Pc, Mouse, Electric Board, Printer and etc Now you may think why I included hardware and explained?. The reason is without hardware software won't work same as without related software hardware won't work.  What is system software?  It is the software that used to manage computer resources and essential for the computer to work. It will install automatically when OS installed. See the image OS and utilities are applied in hardware then only it will work. Types: BIOS Ut...

What is Windows Service?

A Windows service is a Computer Program It enables to create long-running executable applications. It doesn't have any User Interfaces only running in the background process. It will run automatically when system boots ON and also we can set manually for Start and Stop Only one instance of windows service running on the device. It will run only administrator privileges. Are you looking my page using system or laptop?. Then you can see a lot of windows services that are running on your system background without your permission, Just follow my instructions Click "Start">Type "Services">Now you can see a lot of window services like below  WHAT IS THE WINDOWS SERVICES CONTROL MANAGER? Windows Services are managed via the Services Control Manager Panel.The Panel shows a list of services that are running on your system/laptop and for each Name, Description(Purpose of service), Status(Started or Not), Startup Type(Ma...