Reputation: 3689
I have NLog configuration like below.
It prints name of thread if it exists. Otherwise I get empty string instead of thread name.
Question: how can I archive behavior below?
threadid
NLog variable).Current configuration example:
<variable name="defaultLayout" value="${date} ${level} [${threadname}] ${logger} - ${message} ${exception:format=ToString}"/>
<targets async="true">
<target name="ConsoleAppender"
type="ColoredConsole"
layout="${var:defaultLayout}" />
</targets>
Please note: I'd like to avoid printing both variables, e.g. this layout of not useful: ... [${threadname}-${threadid}] ...
Upvotes: 8
Views: 5677
Reputation: 3689
TLDR: use this - ${threadname:whenEmpty=${threadid}}
So right configuration:
<variable name="defaultLayout" value="${date} ${level} [${threadname:whenEmpty=${threadid}}] ${logger} - ${message} ${exception:format=ToString}"/>
<targets async="true">
<target name="ConsoleAppender"
type="ColoredConsole"
layout="${var:defaultLayout}" />
</targets>
Upvotes: 11