如何使用 NLog 错误记录获取以下输出格式;每个异常日志之间的行分隔符。等;
2017-06-19 16:53:20|SessionVal| Error message| Exception's Message | StackTrace
_______________________________________________________________________________________ 2017-06-19 16:52:10|SessionVal|Error occured while executing the procedure.
|Procedure xyz expects varchar(20) @ParameterName.|StackTrace....
当前的NLog配置;
<nlog autoReload="true" xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="logfile" xsi:type="File"
layout="${date:universalTime=false:format=yyyy-MM-dd HH\:mm\:ss}|
${aspnet- session:Variable=SessionKey} ${message} |
${exception:format=type,message,StackTrace}"
fileName="${basedir}/App_Data/Log/
${date:universalTime=false:format=yyyyMMdd}.log" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logfile" />
</rules>
</nlog>
更新: @Amy,你是这样说的;
更新2:谢谢@Amy工作。
layout="--------------------------------------------------------------
${newline}${date:universalTime=false:format=yyyy-MM-dd HH\:mm\:ss}|
${aspnet- session:Variable=SessionKey} ${message} |
${exception:format=type,message,StackTrace}"
fileName="${basedir}/App_Data/Log/
${date:universalTime=false:format=yyyyMMdd}.log"
答案 0 :(得分:-1)
根据问题的质询者,这是一个解决方案:
layout="--------------------------------------------------------------
${newline}${date:universalTime=false:format=yyyy-MM-dd HH\:mm\:ss}|
${aspnet- session:Variable=SessionKey} ${message} |
${exception:format=type,message,StackTrace}"
fileName="${basedir}/App_Data/Log/
${date:universalTime=false:format=yyyyMMdd}.log"