Wenn ich das Standardlayout mit NLog verwende, wird nur der Name der Ausnahme ausgegeben. Mir wurde gesagt, dass das log4jxmlevent-Layout nichts über die Ausnahme ausgibt. Welches Layout wird mir helfen?Wie erhält man den Stack-Trace beim Loggen von Exceptions mit NLog?
Beispielcode:
try
{
throw new SystemException();
}
catch (Exception ex)
{
logger.Error("oi", ex);
}
Standard-Layout Ausgabe:
2011-01-14 09:14:48.0343|ERROR|ConsoleApplication.Program|oi
log4jxmlevent Ausgang:
<log4j:event logger="ConsoleApplication.Program"
level="ERROR"
timestamp="1295003776872"
thread="9">
<log4j:message>oi</log4j:message>
<log4j:NDC />
<log4j:locationInfo class="ConsoleApplication.Program"
method="Void Main(System.String[])"
file="C:\Users\User\Documents\Visual Studio 2010\Projects\ConsoleApplication\ConsoleApplication\Program.cs"
line="21" />
<nlog:eventSequenceNumber>3</nlog:eventSequenceNumber>
<nlog:locationInfo assembly="ConsoleApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<log4j:properties>
<log4j:data name="log4japp"
value="true" />
<log4j:data name="log4jmachinename"
value="MACHINE" />
</log4j:properties>
Ist dies zusätzlich zu einem bestehenden Layout? – Shane
@Shane sicherlich, es sei denn, Sie brauchen nur die Stack-Trace –
FYI, dieser Ansatz ist veraltet. https://github.com/NLog/NLog/wiki/How-to-Log-Exceptions – Clay