public static void SetupConfigLoggers() { bool logToFile = Boolean.Parse(ConfigurationManager.AppSettings["logToFile"]); if (!logToFile) { return; } string sectionName = "loggerSection"; try { LoggerSection lSection = (LoggerSection)ConfigurationManager.GetSection(sectionName); LoggerCollection lCol = lSection.Loggers; foreach (LoggerConfigElement lElement in lCol) { LoggerSpec logFile = new LoggerSpec(); logFile.name = lElement.loggerName; logFile.level = Logger.Level.Info; logFile.dateFormat = "{0:dd/MM/yyyy H:mm:ss zzz} : "; logFile.logType = Logger.LogType.File; logFile.fileName = Path.Combine(lElement.path, lElement.fileBaseName); Logger.Instance.AppendLoggerSpec(logFile); Console.Out.WriteLine(lElement.loggerName); } } catch (Exception ex) { Console.Out.WriteLine(ex.Message); } }
static void setupLoggers() { // normal console writer. LoggerSpec outConsole = new LoggerSpec(); outConsole.name = LoggerDefine.OUT_CONSOLE; outConsole.level = Logger.Level.Info; outConsole.dateFormat = "{0:dd/MM/yyyy H:mm:ss zzz} : "; outConsole.logType = Logger.LogType.Console; Logger.Instance.AppendLoggerSpec(outConsole); // debug console writer. LoggerSpec debugConsole = new LoggerSpec(); debugConsole.name = LoggerDefine.DEBUG_CONSOLE; debugConsole.level = Logger.Level.Info; debugConsole.dateFormat = "{0:dd/MM/yyyy H:mm:ss zzz} : "; debugConsole.logType = Logger.LogType.Console; Logger.Instance.AppendLoggerSpec(debugConsole); }
public void AppendLoggerSpec(LoggerSpec spec) { if (!loggers.ContainsKey(spec.name)) { loggers.TryAdd(spec.name, new Log()); } if ((spec.logType & Logger.LogType.Console) != 0) { getLog(spec.name).Add(new LogWriterConsole(spec.level, spec.dateFormat)); } if ((spec.logType & Logger.LogType.Error) != 0) { loggers[spec.name].Add(new LogWriterErrorConsole(spec.level, spec.dateFormat)); } if ((spec.logType & Logger.LogType.File) != 0) { loggers[spec.name].Add(new LogWriterFile(spec.fileName, spec.level, spec.dateFormat)); } }
public static void SetupConfigLoggers() { try { bool logToFile = Boolean.Parse(getAppValue("logToFile")); if (!logToFile) { return; } } catch (Exception ex) { Console.Out.WriteLine(ex.Message); return; } try { LoggerSection lSection = (LoggerSection)config.GetSection(ParseConfigManager.LOGGER_SECITON); LoggerCollection lCol = lSection.Loggers; foreach (LoggerConfigElement lElement in lCol) { LoggerSpec logFile = new LoggerSpec(); logFile.name = lElement.loggerName; logFile.level = Logger.Level.Info; logFile.dateFormat = "{0:dd/MM/yyyy H:mm:ss zzz} : "; logFile.logType = Logger.LogType.File; logFile.fileName = Path.Combine(lElement.path, lElement.fileBaseName); Logger.Instance.AppendLoggerSpec(logFile); } } catch (Exception ex) { Console.Out.WriteLine(ex.Message); } }
private static void setupProfileLogger(string loggerToUse) { LoggerSection lSection = (LoggerSection)config.GetSection(ParseConfigManager.LOGGER_SECITON); LoggerCollection lCol = lSection.Loggers; foreach (LoggerConfigElement lElement in lCol) { if (lElement.loggerName != loggerToUse) { continue; } LoggerSpec logFile = new LoggerSpec(); logFile.name = lElement.loggerName; logFile.level = Logger.Level.Info; logFile.dateFormat = "{0:dd/MM/yyyy H:mm:ss zzz} : "; logFile.logType = Logger.LogType.File; logFile.fileName = Path.Combine(lElement.path, lElement.fileBaseName); Logger.Instance.AppendLoggerSpec(logFile); return; } throw new Exception("Logger specified: " + loggerToUse + ", could not be found"); }