0

I want nlog to output newline when message is empty, when message is not empty, I want output layout.
I've tried following approach, but it doesn't work:

<variable name="DefaultLayout" value="${time}  ${level:uppercase=true}: ${message}"/>
<variable name="Main" value="${when:when='${message}'=='':inner=${newline}:else=${DefaultLayout}}"/>
......
<target xsi:type="ColoredConsole" name="console" layout="${Main}" />

In this configuration it prints new line when message is empty, but when message is not empty, it doesn't print this message, only 16:06:34.7274 INFO
How to fix config to have desired effect?

1 Answer 1

2

You need to escape the colon (:) in the variable DefaultLayout with a backslash (\)

2
  • WOW! I saw this in docs, but thought that this is not necessary, since I'm not using direct layout, but reference variable instead. Thanks @Julian for the tip and thanks for your impressive work for Nlog!
    – Kai
    Sep 2, 2016 at 12:28
  • thanks @Kai! FYI, variables are inlined when parsing the config, so they have the same rules as direct usages.
    – Julian
    Sep 2, 2016 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.