public Looger(Level level, LoggerConfigElement element) { if (element == null) { _isFatalEnabled = _isErrorEnabled = _isWarnEnabled = _isDebugEnabled = _isInfoEnabled = false; return; } _isFatalEnabled = level >= Level.Fatal; _isErrorEnabled = level >= Level.Error; _isWarnEnabled = level >= Level.Warn; _isDebugEnabled = level >= Level.Debug; _isInfoEnabled = level >= Level.Info; _element = element; TaxtKeyValue = new Dictionary <string, string>(); TaxtKeyValue.Add("{newline}", Environment.NewLine); TaxtKeyValue.Add("{date}", Format_Date); TaxtKeyValue.Add("{thread}", Format_Thread); TaxtKeyValue.Add("{level}", Format_Level); _currDate = DateTime.Now; string fileName = _element.DatePattern; if (_element.StaticLogFileName == false) { fileName = _currDate.ToString(fileName); } string newPath = Path.Combine(_element.FilePath, fileName); _currFileInfo = new FileInfo(newPath); if (_currFileInfo.Directory.Exists == false) { _currFileInfo.Directory.Create(); } if (_currFileInfo.Exists == false) { _currFileInfo.Create().Dispose(); } _currFileStream = _currFileInfo.Open(FileMode.Append, FileAccess.Write, FileShare.Read); }
public static ILooger GetLogger(string layoutName) { Level level = Level.None; LoggerConfigSection getsection = CustomConfigManager.LoggerConfigSection(); if (getsection == null) { return(new Looger(level, null)); } LoggerConfigElement findelement = getsection.Loggers[layoutName]; if (findelement == null) { return(new Looger(level, null)); } Enum.TryParse(findelement.Level, out level); return(new Looger(level, findelement)); }