Nuget获取包
配置文件
<?xml version="1.0" encoding="utf-8" ?> <nlog xmlns= "http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd" autoReload="true" throwExceptions="false" internalLogLevel="Off" internalLogFile= "c: emp log-internal.log"> <variable name="myvar" value="myvalue"/> <targets> <!--输出到文件--> <target xsi:type="File" name="f" fileName= "D:/${shortdate}.log" layout="${longdate} [${level:uppercase=true}] ${message}" /> <!--VS输出窗口--> <target name="debugger" xsi:type="Debugger" layout="${longdate} [${level:uppercase=true}] ${message}"/> <!--输出到控制台--> <target name="console" xsi:type="Console" layout="${longdate} [${level:uppercase=true}] ${message}"/> </targets> <rules> <logger name="*" minlevel="Trace" writeTo="f" /> <logger name="*" writeTo="debugger"/> <logger name="*" writeTo="console"/> </rules> </nlog>
调用范例
try { int a = 1; int b = 0; int c = a / b; } catch(Exception ex) { Logger _logger = LogManager.GetCurrentClassLogger(); //_logger.Trace("Trace Message"); //_logger.Debug("DebugMessage"); //_logger.Info("InfoMessage"); _logger.Error(ex.Message+ex.StackTrace); //_logger.Fatal("FatalMessage"); }