c# - Writing stack trace to log file only when exception thrown -
i want write stack trace when have exceptions,
layout="${longdate}|${level}|${message} ${exception:format=tostring} | ${stacktrace}"
so in log file.
edit:
i use layout logging, when dont have exceptions stack trace.but need when have exception
when have exception have following output, , need
2011-07-01 22:59:02.3782|debug|fffffffffffffffffffffffffffff system.exception: exception of type 'system.exception' thrown. | appdomain.executeassembly => appdomain._nexecuteassembly => program.main
but without exception :
2011-07-01 22:57:26.7117|trace|fffffffffffffffffffffffffffff | appdomain.executeassembly => appdomain._nexecuteassembly => program.main
but want only
2011-07-01 22:57:26.7117|trace|fffffffffffffffffffffffffffff
need ideas how so...
yes, in nlog can use different levels warn, error info etc. can log exceptions errorexception, warnexception, infoexception. ie
logger.error("this error message");
if want show exception use following.
logger.errorexception("this error exception", e);
update :
<target name="errors" xsi:type="file" filename="${logdirectory}/errorlog.txt" layout="${longdate} ${message} ${exception:format=tostring}"/>
remove {stacktrace}
update :
exception e = new exception(); e.stacktrace // <= exception holds stack trace
you stacktrace exception.
Comments
Post a Comment