我将 Common.Logging 与 NLog 适配器一起使用。
http://netcommon.sourceforge.net/docs/1.2.0/reference/html/logging.html
我正在调用这个方法:
void Error( object message, Exception exception );
“消息”的文本显示在日志(一个 txt 文件和事件日志中)中,但有关异常的详细信息没有。甚至没有前消息。
我错过了什么吗?
如何获取有关异常的详细信息以显示。我是否必须将其附加在“对象信息”上?我猜想有例外的重载方法,我认为会有一些自动记录。
我的 NLog.config 相当简单。
<nlog 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" fileName="MyFile.log.txt"/>
<target name="console" xsi:type="Console" />
<target xsi:type="EventLog"
name="eventLog"
source="MySource"
eventId="555"
log="Application"
/>
</targets>
<rules>
<logger name="*" minLevel="Error" writeTo="eventLog" />
<logger name="*" minLevel="Info" writeTo="console" />
<logger name="*" minLevel="Info" writeTo="logfile"/>
</rules>
</nlog>
编辑:
好的......根据谢尔盖的回答,我刚刚完成了我的设置:
layout="${longdate}|${level}|${callsite}|${logger}|${threadid}|${windows-identity:domain=false}__${message} ${exception:format=message,stacktrace:separator=*"