I have this XML log4net configuration:
<log4net>
<appender name="myAppender" type="log4net.Appender.RollingFileAppender">
<file value="mylog.txt" />
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="myAppender" />
</root>
</log4net>
I load this configuration with the C# line below, and it works well:
log4net.Config.XmlConfigurator.Configure(path);
PROBLEM: Now I want to set the lockingModel
to MinimalLock
. Programmatically, not in XML.
How to do it?
That would be the equivalent of adding <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
in the XML configuration.
// assumes there are not multiple file appenders defined
var appender = log4net.LogManager.GetRepository()
.GetAppenders()
.OfType<FileAppender>()
.SingleOrDefault();
if (appender != null)
{
appender.LockingModel = new FileAppender.MinimalLock();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With