Changing parameters at runtime for log4net is fairly simple - see the following code sample:
///
/// SMTP Appender custom configuration
///
public void InitializeLog4Net()
{
//We need access to the repositories for the loggers
ILoggerRepository repository = LogManager.GetRepository();
//Get only SmtpAppenders
//can do it as such:
//var appenders = repository.GetAppenders().Where(o => o is SmtpAppender).Select(o => (SmtpAppender)o);
//Or a bit more readable
var appenders= from o in repository.GetAppenders()
where o is SmtpAppender
select (SmtpAppender)o;
foreach (SmtpAppender smtpAppender in appenders)
{
smtpAppender.To = "adam_tuliper@nowhere";
//Make this config change active immediately
smtpAppender.ActivateOptions();
}
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.