public void Initialize(LoggerNames loggerNameEnum, string cacheName) { if (log != null) { throw new Exception("Multiple Initialize calls for same logger"); } MemoryStream logStream = new MemoryStream(log4netXML); log4net.Config.XmlConfigurator.Configure(logStream); _loggerName = loggerNameEnum.ToString(); string filename = _loggerName; if (loggerNameEnum == LoggerNames.ClientLogs) { filename = filename + "." + cacheName + "." + System.Diagnostics.Process.GetCurrentProcess().Id; // changing the name here will invalidate static log checks automatically since LoggerName == ClientLogs _loggerName = cacheName + System.Diagnostics.Process.GetCurrentProcess().Id; } else { filename = cacheName; } filename = string.IsNullOrEmpty(filename) ? string.Empty : filename + "."; filename += DateTime.Now.ToString("dd-MM-yy HH-mm-ss") + "_" + _nodeIP + @".txt"; string filepath = ""; if (!DirectoryUtil.SearchGlobalDirectory("log-files", false, out filepath)) { try { DirectoryUtil.SearchLocalDirectory("log-files", true, out filepath); } catch (Exception ex) { throw new Exception("Unable to initialize the log file", ex); } } try { filepath = Path.Combine(filepath, loggerNameEnum.ToString()); if (!Directory.Exists(filepath)) { Directory.CreateDirectory(filepath); } filepath = Path.Combine(filepath, filename); AddAppender(CreateBufferAppender(filepath)); } catch (Exception) { throw; } }
public void InitializeAPILogging(LoggerNames loggerNameEnum, string cacheName, string filePath) { if (log != null) { throw new Exception("Multiple Initialize calls for same logger"); } MemoryStream logStream = new MemoryStream(log4netXML); log4net.Config.XmlConfigurator.Configure(Log4net.LogRepository, logStream); _loggerName = loggerNameEnum.ToString(); string filename = _loggerName; if (loggerNameEnum == LoggerNames.APILogs) { filename = cacheName; } filename = string.IsNullOrEmpty(filename) ? string.Empty : filename + "."; filename += DateTime.Now.ToString("dd-MM-yy HH-mm-ss") + "_" + _nodeIP + @".txt"; if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } try { filePath = Path.Combine(filePath, filename); AddAppender(CreateBufferAppender(filePath, true, false)); } catch (Exception) { throw; } }
public void Getlogger(LoggerNames loggerNameEnum) { try { _log = LogManager.GetLogger(loggerNameEnum.ToString()); } catch (Exception ex) { AppUtil.LogEvent(ex.ToString(), System.Diagnostics.EventLogEntryType.Error); } }
public static void Log(LoggerNames name, LogLevel level, Exception ex, string message) { NLog.LogLevel nLevel = NLog.LogLevel.FromString(level.ToString()); Log(name.ToString(), level, message, ex); }
public static void SetLevel(LoggerNames loggerEnum, Level level) { string loggerName = LoggingInformation.GetLoggerName(LoggingInformation.GetStaticLoggerName(loggerEnum.ToString())); if (loggerName != null && loggerName.Length > 0) { lock (NCacheLog.syncLock) { log4net.Core.Level lvl; switch (level.ToString().ToLower()) { case "all": lvl = log4net.Core.Level.All; break; case "error": lvl = log4net.Core.Level.Error; break; case "fatal": lvl = log4net.Core.Level.Fatal; break; case "info": lvl = log4net.Core.Level.Info; break; case "debug": lvl = log4net.Core.Level.Debug; break; case "warn": lvl = log4net.Core.Level.Warn; break; case "off": lvl = log4net.Core.Level.Off; break; default: lvl = log4net.Core.Level.All; break; } //If the logger doesnot exist it will create one else fetches one log4net.ILog log = log4net.LogManager.GetLogger(loggerName); //adds the logger as a seperate hierchy, not dependant on any other logger log4net.Repository.Hierarchy.Logger l = (log4net.Repository.Hierarchy.Logger)log.Logger; //Applies the logger threshold level l.Level = l.Hierarchy.LevelMap[level.ToString()]; IAppender[] appenderCol = log.Logger.Repository.GetAppenders(); for (int i = 0; i < appenderCol.Length; i++) { IAppender appender = appenderCol[i]; if (appender != null) { if (appender is BufferingForwardingAppender) { ((BufferingForwardingAppender)appender).Threshold = lvl; } if (appender is RollingFileAppender) { ((RollingFileAppender)appender).Threshold = lvl; } } } } } else { NCacheLog.LogLoggingError("loggerName != null && loggerName.Length > 0"); } }
public static void SetLevel(LoggerNames loggerEnum, Level level) { string loggerName = LoggingInformation.GetLoggerName(LoggingInformation.GetStaticLoggerName(loggerEnum.ToString())); if (loggerName != null && loggerName.Length > 0) { lock (NCacheLog.syncLock) { log4net.Core.Level lvl; switch (level.ToString().ToLower()) { case "all": lvl = log4net.Core.Level.All; break; case "error": lvl = log4net.Core.Level.Error; break; case "fatal": lvl = log4net.Core.Level.Fatal; break; case "info": lvl = log4net.Core.Level.Info; break; case "debug": lvl = log4net.Core.Level.Debug; break; case "warn": lvl = log4net.Core.Level.Warn; break; case "off": lvl = log4net.Core.Level.Off; break; default: lvl = log4net.Core.Level.All; break; } //If the logger doesnot exist it will create one else fetches one log4net.ILog log = log4net.LogManager.GetLogger(loggerName); //adds the logger as a seperate hierchy, not dependant on any other logger log4net.Repository.Hierarchy.Logger l = (log4net.Repository.Hierarchy.Logger)log.Logger; //Applies the logger threshold level l.Level = l.Hierarchy.LevelMap[level.ToString()]; IAppender[] appenderCol = log.Logger.Repository.GetAppenders(); for (int i = 0; i < appenderCol.Length; i++) { IAppender appender = appenderCol[i]; if (appender != null) { if (appender is BufferingForwardingAppender) { ((BufferingForwardingAppender)appender).Threshold = lvl; } if (appender is RollingFileAppender) { ((RollingFileAppender)appender).Threshold = lvl; } } } } } else { NCacheLog.LogLoggingError("loggerName != null && loggerName.Length > 0"); } }
public void Initialize(LoggerNames loggerNameEnum, string cacheName) { if (log != null) throw new Exception("Multiple Initialize calls for same logger"); MemoryStream logStream = new MemoryStream(log4netXML); log4net.Config.XmlConfigurator.Configure(logStream); _loggerName = loggerNameEnum.ToString(); string filename = _loggerName; if (loggerNameEnum == LoggerNames.ClientLogs) { filename = filename + "." + cacheName + "." + System.Diagnostics.Process.GetCurrentProcess().Id; // changing the name here will invalidate static log checks automatically since LoggerName == ClientLogs _loggerName = cacheName + System.Diagnostics.Process.GetCurrentProcess().Id; } else { filename = cacheName; } filename = string.IsNullOrEmpty(filename) ? string.Empty : filename + "."; filename += DateTime.Now.ToString("dd-MM-yy HH-mm-ss") + "_" + _nodeIP + @".txt"; string filepath = ""; if (!DirectoryUtil.SearchGlobalDirectory("log-files", false, out filepath)) { try { DirectoryUtil.SearchLocalDirectory("log-files", true, out filepath); } catch (Exception ex) { throw new Exception("Unable to initialize the log file", ex); } } try { filepath = Path.Combine(filepath, loggerNameEnum.ToString()); if (!Directory.Exists(filepath)) Directory.CreateDirectory(filepath); filepath = Path.Combine(filepath, filename); AddAppender(CreateBufferAppender(filepath)); } catch (Exception) { throw; } }