1

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?

Denis535
  • 3,407
  • 4
  • 25
  • 36

2 Answers2

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

Julian
  • 33,915
  • 22
  • 119
  • 174
0

It looks like no another ways to use different layout with one target.

And probably better just to use custom layout.

Denis535
  • 3,407
  • 4
  • 25
  • 36