Modifying log4net settings

Here’s how to modify log4net settings from a config file before initializing log4net. This can be useful for example if you have encrypted connection strings in App.config and have to decrypt them before passing them to log4net.

XmlElement log4NetSection = (XmlElement)ConfigurationManager.GetSection("log4net");

// Modify the xml, e.g. by adjusting the InnerXml property...
log4NetSection.InnerXml = StringCrypto.DecryptTaggedString(mypwd, log4NetSection.InnerXml);

XmlConfigurator.Configure(log4NetSection);

/Emil

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.