问题
I saw this old question: How to apply different layouts to the same target in NLog?
The answer was: to use different targets for different levels. I'm not sure this will always work correctly.
A lot of time has passed since. Maybe now there is a better way?
回答1:
You could create a custom layout, which has conditions. It will look like the CompoundLayout
e.g.
<layout type='ConditionalLayout'>
<if condition="">
<layout type='JsonLayout'> ...</layout>
</if>
<if condition="">
<layout type='JsonLayout'> ...</layout>
</if>
</layout>
The code file for CompoundLayout
is here: https://github.com/NLog/NLog/blob/dev/src/NLog/Layouts/CompoundLayout.cs
回答2:
It looks like no another ways to use different layout with one target.
And probably better just to use custom layout.
来源:https://stackoverflow.com/questions/54747376/nlog-how-to-use-different-layout-for-different-levels