Dynamically setting a log4net property using common.logging

Posted by Kyle LeNeau on Stack Overflow See other posts from Stack Overflow or by Kyle LeNeau
Published on 2010-01-22T16:15:27Z Indexed on 2010/03/25 0:03 UTC
Read the original article Hit count: 369

Filed under:
|
|
|

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>

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

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.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about logging