Tuesday, July 23, 2013

Override the log4net.config specifications for sending emails from C#.

My boss found this and this and concluded that these settings may be superseded splendidly from within code. He was right! Observe:

log4net.Repository.Hierarchy.Hierarchy hierarchy = log4net.LogManager.
      GetLoggerRepository() as log4net.Repository.Hierarchy.Hierarchy;
log4net.Appender.SmtpAppender appender = (log4net.Appender.SmtpAppender)
      hierarchy.GetAppenders().Where(x => x.GetType() == typeof(log4net.Appender.
      SmtpAppender)).FirstOrDefault();
appender.Subject = "maybe THIS will get your attention";
appender.ActivateOptions();

 
 

This just has to happen somewhere upstream of log4net logging attempts.

No comments:

Post a Comment