在Log4Net中,XML配置优先级与Level相同吗?

栏目: ASP.NET · 发布时间: 5年前

内容简介:翻译自:https://stackoverflow.com/questions/24172777/in-log4net-xml-configuration-is-priority-the-same-thing-as-level
我继承了一些代码,它在xml configuraiton的根目录下使用了priority元素.这就像 http://iserialized.com/log4net-for-noobs/

的例子所示:

<root>
 <priority value="ALL" />
 <appender-ref ref="LogFileAppender" />
 <appender-ref ref="ConsoleAppender"/>
</root>

但是, http://logging.apache.org/log4net/release/manual/configuration.html 中的log4net配置示例始终使用level元素显示它:

<root>
 <level value="DEBUG" />
 <appender-ref ref="A1" />
</root>

在这种类型的配置是

<priority>

同样的

<level>

有人能指出我在解释这个问题的文档中的某个地方吗?

log4net中的Logger类没有Priority属性.我可以找到的优先级的唯一实例是在SmtpAppender中.所以进入代码我去了!

在XmlHierarchyConfigurator的ParseChildrenOfLoggerElement方法中,您将找到以下代码:

if (xmlElement.LocalName == "level" || xmlElement.LocalName == "priority")
{
    this.ParseLevel(xmlElement, log, isRoot);
}

啊!这两个值都被解析为相同的属性(ParseLevel方法除了分配,记录和管理“继承”值(这是一个可能的级别)之外并没有那么多,所以你有它; “level”和“priority”对您的配置具有完全相同的效果.我想这是为了保持与先前版本的库的某种向后兼容性,事实上它是由 this article about log4j 支持的:

In early versions of log4j, these were called category and priority,  but now they’re called logger and level, respectively.

实际上,如果我们搜索“category”,XmlHierarchyConfigurator中有一个Configure方法,它包含以下代码:

// ...
XmlElement xmlElement = (XmlElement)xmlNode;
if (xmlElement.LocalName == "logger")
{
    this.ParseLogger(xmlElement);
}
else
{
    if (xmlElement.LocalName == "category")
    {
        this.ParseLogger(xmlElement);
    }
    else
    {
        if (xmlElement.LocalName == "root")
        {
            this.ParseRoot(xmlElement);
        }
    // ...

就是这样:级别和优先级可以互换,记录器和类别也是如此.

有趣的花絮:最后一个属性获胜,并且对于您在记录器上可能拥有的属性数量没有限制,因此这是有效的并且将级别设置为DEBUG

<root>
 <priority value="ALL" />
 <priority value="ERROR" />
 <level value="DEBUG" />
</root>

翻译自:https://stackoverflow.com/questions/24172777/in-log4net-xml-configuration-is-priority-the-same-thing-as-level


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Sexy Web Design

Sexy Web Design

Elliot Stocks / SitePoint / 2009-03-28 / $39.95

Description A guide to building usable, aesthetically pleasing interfaces for web sites and web applications by applying timeless principles of user-centered design. This book focuses on practical ......一起来看看 《Sexy Web Design》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具