public void Config(string[] domains, IZicEmailConfig emailConfig) { foreach (string domain in domains) { ILoggerRepository repository = LogManager.CreateRepository(domain); //FileLog foreach (KeyValuePair<string, LevelRangeFilter> Filter in Filters) { RollingFileAppender fileAppender = new RollingFileAppender(); fileAppender.Name = domain + "_" + Filter.Key + "_FileAppender"; fileAppender.File = "Log_" + domain + "\\" + Filter.Key + "\\"; fileAppender.AppendToFile = true; fileAppender.RollingStyle = RollingFileAppender.RollingMode.Date; fileAppender.DatePattern = "yyyy-MM-dd'.log'"; fileAppender.StaticLogFileName = false; fileAppender.Layout = ZicLayout; fileAppender.AddFilter(Filter.Value); fileAppender.ActivateOptions(); BasicConfigurator.Configure(repository, fileAppender); } //SmtpLog ZicSmtpAppender smtpAppender = new ZicSmtpAppender(emailConfig); smtpAppender.Name = domain + "_SmtpAppender"; smtpAppender.Authentication = ZicSmtpAppender.SmtpAuthentication.Basic; smtpAppender.Subject = domain + " logging message"; //zic:邮件日志与其他日志同级别(甚至更高),所以不允许丢失或缓冲,所以Buffer、lossy、Evaluator全部忽略 //如果缓冲区溢出在触发事件之前,日志事件可能会丢失。 //如果log4net.Appender.BufferingAppenderSkeleton.Lossy设置为false防止日志事件被丢失。 //如果log4net.Appender.BufferingAppenderSkeleton.Lossy设置为true,那么log4net.Appender.BufferingAppenderSkeleton.Evaluator必须被指定。 //也就是说如果LevelEvaluator设为WARN,则在WARN或之上级别的日志肯定不会丢失,之下级别的日志有可能因为缓冲区溢出而丢失。 smtpAppender.BufferSize = 0; smtpAppender.Lossy = false; smtpAppender.Layout = ZicLayout; smtpAppender.AddFilter(EmailFilter); smtpAppender.ActivateOptions(); BasicConfigurator.Configure(repository, smtpAppender); } }
public ZicSmtpAppender(IZicEmailConfig config) { To = config.To; From = config.From; Username = config.Username; Password = config.Password; EnableSSL = config.EnableSSL; SmtpHost = config.SmtpHost; Port = config.Port; }