I create my own layout in NLog.config
file:
<variable name="MyLayout" value="${message}: ${exception:format=tostring}"/>
But when there is no exception I still see :
after message and nothing after it in my log file.
How could I add :
only if there is an exception? Maybe something like this (not working code) :
<variable name="MyLayout" value="${message}${exception != null ? ': ' : ''}${exception:format=tostring}"/>
You can do this with ${message}
${message:exceptionSeparator= \: :withException=true}
Or you can use ${onexception}
${message}${onexception: \: }${exception:format=tostring}
Notice :
is used as option-delimiter for NLog LayoutRenderer, so it has to be escaped .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.