动态设置使用common.logging一个log4net的财产财产、动态、logging、common

2023-09-03 21:04:50 作者:农村卡哇伊

有谁知道是否有在Common.Logging等效(用于.NET)来设置log4net的工厂适配器属性?我有只使用log4net的做,当巨大的成功:

Does anyone know if there is an equivalent in Common.Logging (for .Net) to set properties for the log4net factory adapter? I have had great success when just using log4net by doing:

<appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
    <file type="log4net.Util.PatternString" value="logs\Log_%property{BrokerID}.txt"/>
    <appendToFile value="false"/>
    <rollingStyle value="Size"/>
    <maxSizeRollBackups value="-1"/>
    <maximumFileSize value="50GB"/>
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date %-5level %logger - %message%newline"/>
    </layout>
</appender>

和设置属性,如: log4net.GlobalContext.Properties [BrokerID] = 10

我结束了与看起来像这样的文件: LOG_(空).TXT 使用common.logging要连接的log4net在飞行时

The file I end up with the looks like this: Log_(null).txt when using the common.logging to wire up log4net on the fly.

推荐答案

请参阅我的answer到previous问题。也许这将帮助,也许不是。

See my answer to a previous question. Maybe it will help, maybe not.

要总结一下:

Common.Logging(NET)表示,其网站的背景的支持计划对于下一个版本。

Common.Logging (NET) says on its website that support for "context" is planned for the "next" release.

目前尚不清楚在网站时,下一个版本(目前的版本是2.0)定。该网站六一说。当前版本(2.0)是2009年4月该网站于2009年5月(也许宣布2.0)最后更新?什么是六一是什么意思? 2009年6月? 2010年6月?两人都来去匆匆。

It is not clear on the website when the next release (the current release is 2.0) is scheduled. The website says "June". The current release (2.0) was April 2009. The website was last updated in May 2009 (maybe to announce 2.0)? What does "June" mean? June 2009? June 2010? Both have come and gone.

由于背景的支持尚不可用的Common.Logging,看看在城堡项目的背景的实施(log4net的实现是这里)。它不会是很难端口实施Common.Logging。一个风险是,上下文实现,最终来自Common.Logging可能不是类似城堡的执行情况。

Given that "context" support is not available yet in Common.Logging, take a look at the "context" implementation in the Castle project (log4net implementation is here). It would not be hard to port that implementation to Common.Logging. A risk is that the context implementation that eventually comes from Common.Logging might not be similar to the Castle implementation.

城堡上下文支持器ILOG / ILogger接口上实现的。因此,而不是设置的情况下是这样的:

The Castle "context" support is implemented on the ILog/ILogger interface. So, rather than setting the context like this:

通过直log4net的访问方面:

Access to context via straight log4net:

log4net.GlobalContext.Properties["BrokerID"] = 10;

通过日志抽象访问方面:

Access to context via logging abstraction:

ILog logger = Common.Logging.LogManager.GetCurrentClassLogger();
logger.GlobalContext.Properties["BrokerID"] = 10;

这似乎是pretty的距离设置的背景下,当你有一个记录器的角度好。也许不是那么好,如果你只是想设置环境,而不必得到了记录。如果Common.Logging.LogManager知道抽象是主动(它应该因为抽象是通过LogManager.Adapter属性可设置/ gettable)。所以,也许上下文可以是可从ILog的界面以及从LogManager.Adapter接口

This seems pretty good from the perspective of setting the context when you have a logger. Maybe not so good if you just want to set the context without having gotten a logger. If the Common.Logging.LogManager knows what abstraction is "active" (and it should because the abstraction is settable/gettable via the LogManager.Adapter property). So, maybe the "context" could be available from the ILog interface as well as from the LogManager.Adapter interface.