Dynamically setting a log4net property using common.logging
- by Kyle LeNeau
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.