How to apply different layouts to the same target in NLog?

后端 未结 2 1550
无人及你
无人及你 2021-02-15 10:07

NLog allows me to use SplitGroup to log my messages to several targets. I\'d like to use this feature to log each message to a common, user-specific and date-specific lo

2条回答
  •  失恋的感觉
    2021-02-15 10:52

    An alternate solution is to use the when condition in the layout.

    target.Layout = "${longdate}|[${level}]|${logger}|${message}${onexception:inner=|${exception}${when:when=(level > LogLevel.Warn):inner=|[!] ${exception:format=ToString:innerFormat=Message:maxInnerExceptionLevel=5} }}"
    

    I wanted to just provide the exception message when anything less than error. When there was an error I wanted full stack trace.

提交回复
热议问题