使用案例:
配置文件:
1 <?xml version="1.0" encoding="utf-8" ?> 2 <configuration> 3 <configSections> 4 <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/> 5 </configSections> 6 <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 7 <targets> 8 <target name="file" xsi:type="File" fileName="${shortdate}.txt" 9 layout="${date:format=HH\:mm\:ss}-${stacktrace}-${message}"/> 10 </targets> 11 <rules> 12 <logger name="*" minlevel="Error" writeTo="file"/> 13 </rules> 14 </nlog> 15 </configuration>
调用:
1 string message = "这是一个异常消息"; 2 NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); 3 logger.Error(message);
相关介绍链接:
http://nlog-project.org/
https://github.com/nlog/nlog/wiki/Configuration-file
http://www.cnblogs.com/dflying/archive/2006/12/06/584426.html(翻译版)