Dynamically defining a log4net property using common.logging

Does anyone know if there is an equivalent in Common.Logging (for .Net) for setting properties for the log4net factory adapter? I was very successful when I just used log4net:

<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>

and setting the property as: log4net.GlobalContext.Properties["BrokerID"] = 10

In this file, I get the following: Log_(null).txtwhen using common.logging to connect log4net log on the fly.

+3
source share
3 answers

See my answer to the previous question. Maybe this will help, maybe not.

Summarizing:

  • Common.Logging(NET) -, "" "" .

  • -

  • , "" Common.Logging, "" Castle ( log4net ). Common.Logging. , , Common.Logging, Castle.

  • "" ILog/ILogger. , , :

log4net:

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

:

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

, . , , , . Common.Logging.LogManager , "" ( , / LogManager.Adapter). , , "" ILog, LogManager.Adapter.

+3

Common.Logging .

GitHub NuGet.

/.

+2

, common.logging, common.logging , log4net, NLog, EntLib .., ( ). , common.logging (ILog), ( log4net). , BrokerID, , .

0

Source: https://habr.com/ru/post/1729587/


All Articles