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.