/// <summary> /// 构造函数 /// </summary> /// <param name="config">配置对象</param> public AppenderBase(BaseConfig config) { if (config == null) { config = this.CreateConfig(null); } this._config = config; this.Init(); }
/// <summary> /// 验证日志是否允许输出[返回值true:允许输出;false:丢弃] /// </summary> /// <param name="config">配置</param> /// <param name="item">要验证输出的日志项</param> /// <returns>true:允许输出;false:丢弃</returns> protected virtual bool Validate(BaseConfig config, LogItem item) { if (item == null) { return(false); } if (!config.Enable) { return(false); } if (config.Levels != null && !config.Levels.Contains(item.Level)) { return(false); } if (config.EventIdMin != LogConstant.DEFAULT_EVENT_ID && item.EventID < config.EventIdMin) { return(false); } if (config.EventIdMax != LogConstant.DEFAULT_EVENT_ID && item.EventID > config.EventIdMax) { return(false); } var matchString = config.MatchString; if (!string.IsNullOrEmpty(matchString) && !string.IsNullOrEmpty(item.Content) && !Regex.IsMatch(item.Content, matchString)) { return(false); } var matchExceptionType = config.MatchExceptionType; if (matchExceptionType != null && item.Exception != null) { Type exType = item.Exception.GetType(); if (exType != matchExceptionType && !exType.IsSubclassOf(matchExceptionType)) { return(false); } } return(true); }
/// <summary> /// 构造函数 /// </summary> /// <param name="config">配置对象</param> public MailAppender(BaseConfig config) : base(config) { }
/// <summary> /// 构造函数 /// </summary> /// <param name="config">配置对象</param> public FileAppender(BaseConfig config) : base(config) { this.Init(); }
/// <summary> /// 构造函数 /// </summary> /// <param name="config">配置对象</param> public DatabaseAppender(BaseConfig config) : base(config) { }
/// <summary> /// 构造函数 /// </summary> /// <param name="ele">配置元素</param> public AppenderBase(XElement ele) { this._config = this.CreateConfig(ele); this.Init(); }
/// <summary> /// 构造函数 /// </summary> /// <param name="config">配置对象</param> public SystemLogAppender(BaseConfig config) : base(config) { }
/// <summary> /// 构造函数 /// </summary> /// <param name="config">配置对象</param> public RedirectAppender(BaseConfig config) : base(config) { this._redirectAppendConfig = (RedirectAppendConfig)base._config; }
/// <summary> /// 构造函数 /// </summary> /// <param name="config">配置对象</param> public ConsoleAppender(BaseConfig config) : base(config) { this._consoleAppenderConfig = (ConsoleAppenderConfig)base._config; }