seb49
seb49

Reputation: 107

Setting up Log4Net appender in another file than the main config file

I want to put an appender section in another file than my main log4net config file.

The goal is to allow me to publish my application with a log4net.config but not erase some customers specific information like smtp parameters.

THe idea is to have :

  <logger name="DatabaseLogger">    
    <level value="ALL" />
    <appender-ref ref="AdoNetAppender" />
    <appender-ref ref="SmtpAppender" />
  </logger>

 <appender configSource="log4netsmtp.config"/>

the log4netsmtp.config is build by the customers for security reasons (with my help) and never change by me.

Sorry for my english and thanks you to read me.

Regards

Upvotes: 1

Views: 301

Answers (1)

Andrea Colleoni
Andrea Colleoni

Reputation: 6021

You can load it through Assembly's GetManifestResourceStream to get your file and treat it like an xml, then to init your logger you can use the log4net.config.XmlConfigurator class and pass to it you XmlElement instance or append your XmlElement to an existing log4net xml configuration:

Assembly a = Assembly.GetAssembly(this.GetType());
Stream stream = a.GetManifestResourceStream("MyAssembly.ConfigFolder.logger.config");
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(stream);
// eventually append, modify, merge, check the xml with other info
XmlConfigurator.Configure(xmlDoc);

Upvotes: 1

Related Questions