NLog:如何对不同级别使用不同的布局? [英] NLog: How to use different layout for different levels?

查看:219
本文介绍了NLog:如何对不同级别使用不同的布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了这个老问题: 如何在NLog?

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?

推荐答案

您可以创建具有条件的自定义布局.看起来像 CompoundLayout

You could create a custom layout, which has conditions. It will look like the CompoundLayout

例如

<layout type='ConditionalLayout'>
    <if condition="">
        <layout type='JsonLayout'> ...</layout>
    </if>
    <if condition="">
        <layout type='JsonLayout'> ...</layout>
    </if>

</layout>

CompoundLayout的代码文件在这里: https://github.com/NLog/NLog/blob/dev/src/NLog/Layouts/CompoundLayout.cs

The code file for CompoundLayout is here: https://github.com/NLog/NLog/blob/dev/src/NLog/Layouts/CompoundLayout.cs

这篇关于NLog:如何对不同级别使用不同的布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆