Nlog Log Management tool--Getting Started example

Source: Internet
Author: User

Nlog Log Management tool

--Output log to Folder 1, create a console application by vs.


2, open the Package Manager console. The actions are as follows: Tools, library Package Manager, Package Manager console.

3, in the Package Manager console input command: Install-package Nlog after the installation is successful, the project's reference will automatically add Nlog this reference. And the project's folder downloads some of the Nlog resource files.


4, continue to enter the command in the Package Manager console: Install-package nlog.config a moment, you will find that the project more than three files, respectively, Nlog.config, Nlog.xsd and Packages.config. Where Nlog.config is the primary configuration file for Nlog to run.

5, now the Nlog.config file for detailed configuration, because this article is only to illustrate the log with Nlog file output, so only a simple configuration of nlog.config, detailed as follows:

Note: Some of the configuration instructions are as follows

<!--Description:

Xsi:type= "File" specifies the output to the file type;

The name = "File_info" specifies the target;

Filename= "${basedir}/logs/nlogblog_${level}_${shortdate}.txt" specifies the specific name of the output file.

Where ${basedir} means the path where the program is located; ${level} means the level of the log; ${shortdate} means date (specific to day).

Layout= "${longdate} ${message}" Specifies the style of the output file contents (freely defined);

Where ${longdate} means the date (specific to milliseconds), ${message} is the content you want to output specifically.

-->

6, to this step, nlog configuration has been completed and then just write the code on the line. The code is as follows:

Using System;

UsingSystem.Collections.Generic;

Using System.Linq;

Using System.Text;

Using System.Threading.Tasks;

Namespace Nlogbolg

{

Classprogram

{

publicstatic Nlog.logger Logger = NLog.LogManager.GetCurrentClassLogger ();

Staticvoid Main (string[] args)

{

Output a log to the folder

Program.logger.Info ("This is Info message!");

Program.logger.Debug ("This is Debug message!");

Program.logger.Warn ("This is Warn message!");

Program.logger.Error ("This is Error message!");

Program.logger.Trace ("This is Trace message!");

Console.readkey ();

}

}

}

7, run the program, the results are as follows:


share happiness.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.