NLog: How to use different layout for different levels?

不羁岁月 提交于 2019-12-13 03:33:18

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!