I want to write the stack trace only when I have exceptions, currently I do it like this
layout="${longdate}|${level}|${message} ${exception:format=tostring} | ${stacktrace}"
So I always get it in my log file.
EDIT:
I use this layout for all my logging, so when I dont have any exceptions I also get the stack trace.But I need it only when i have some exception
when I have an exception I have following output, and it what I need
2011-07-01 22:59:02.3782|Debug|fffffffffffffffffffffffffffff System.Exception: Exception of type 'System.Exception' was 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 I want only
2011-07-01 22:57:26.7117|Trace|fffffffffffffffffffffffffffff
Need ideas how to do so…
Yes, in NLog you can use different levels Warn, Error Info etc. You can also log the exceptions with ErrorException, WarnException, InfoException. IE
If you want to show the exception then use the following.
Update :
Remove {stacktrace}
Update :
You will get the stacktrace from the exception.