Пример #1
0
        public static void Warn(NCacheLog.LoggerNames loggerName, String module, String message)
        {
            string name = loggerName.ToString();;

            if (loggerName != LoggerNames.ClientLogs)
            {
                name = LoggingInformation.GetStaticLoggerName(loggerName.ToString());
            }
            Warn(name, module, message);
        }
Пример #2
0
        public static void CriticalInfo(NCacheLog.LoggerNames loggerName, string message)
        {
            string name = loggerName.ToString();;

            if (loggerName != LoggerNames.ClientLogs)
            {
                name = LoggingInformation.GetStaticLoggerName(loggerName.ToString());
            }
            CriticalInfo(name, message);
        }
Пример #3
0
        public static void OnChange()
        {
            bool[] logLevel   = new bool[2];
            int    bufferSize = bufferDefaultSize;

            lock (syncLock)
            {
                if (_timeFired != null)
                {
                    if (DateTime.Now.Subtract(_timeFired).TotalMilliseconds < 50)
                    {
                        return;
                    }
                }
                _timeFired = DateTime.Now;


                System.Configuration.ConfigurationManager.RefreshSection("appSettings");
                logLevel = ReadConfig(out bufferSize);
            }

            string loggerName = LoggingInformation.GetStaticLoggerName(LoggerNames.SocketServerLogs.ToString());

            if (loggerName != null)
            {
                log4net.ILog log = log4net.LogManager.GetLogger(loggerName);
                log4net.Repository.Hierarchy.Logger l = (log4net.Repository.Hierarchy.Logger)log.Logger;

                BufferingAppenderSkeleton buffered = (BufferingAppenderSkeleton)l.GetAppender("BufferingForwardingAppender" + loggerName);
                if (buffered is BufferingForwardingAppender)
                {
                    ((BufferingForwardingAppender)buffered).Flush();
                }
            }

            //if not already initialized
            Log4net.Initialize(LoggerNames.SocketServerLogs);

            NCacheLog.SetLevel(LoggerNames.SocketServerLogs.ToString(), logLevel[1] == true ? NCacheLog.Level.ALL : logLevel[0] == true ? NCacheLog.Level.INFO : NCacheLog.Level.OFF);

            if (bufferSize < 1)
            {
                bufferSize = bufferDefaultSize;
            }

            NCacheLog.SetBufferSize(bufferSize);
        }
Пример #4
0
        public static bool IsDebugEnabled(NCacheLog.LoggerNames loggerEnum)
        {
            #region isEnabledLogic
            string temp = LoggingInformation.GetStaticLoggerName(loggerEnum.ToString());
            if (temp != null && temp.Length > 0)
            {
                string loggerName = LoggingInformation.GetLoggerName(temp);
                if (loggerName != null && loggerName.Length > 0)
                {
                    log4net.ILog log = log4net.LogManager.GetLogger(loggerName);
                    return(log.IsDebugEnabled);
                }
                else
                {
                    NCacheLog.LogLoggingError("loggerName != null && loggerName.Length > 0");
                }
            }
            return(false);

            #endregion
        }
Пример #5
0
        /// <summary>
        /// intitializes Known name based log files
        /// </summary>
        /// <param name="loggerName">Enum of Known loggerNames</param>
        /// <param name="cacheName">cacheName  use the other override</param>
        public static void Initialize(NCacheLog.LoggerNames loggerNameEnum, string cacheName)
        {
            lock (lockObj)
            {
                MemoryStream logStream = new MemoryStream(log4netXML);
                log4net.Config.XmlConfigurator.Configure(logStream);

                string logName = loggerNameEnum.ToString();

                string filename = logName;
                if (loggerNameEnum == NCacheLog.LoggerNames.ClientLogs && (cacheName != null && cacheName.Length > 0))
                {
                    filename = filename + "." + cacheName + "." + System.Diagnostics.Process.GetCurrentProcess().Id;

                    // changing the name here will invalidate static log checks automatically since LoggerName == ClientLogs
                    logName = cacheName + System.Diagnostics.Process.GetCurrentProcess().Id;
                }
                else
                {
                    if (cacheName != null && cacheName.Length > 0)
                    {
                        filename = cacheName;
                    }
                }

                //If Logger is already present, can either be a cache or Client
                if (LoggingInformation.GetLoggerName(logName) != null)
                {
                    if (loggerNameEnum == NCacheLog.LoggerNames.ClientLogs)
                    {
                        return; // clientLogs alread initiated
                    }
                    else
                    {
                        if (LoggingInformation.GetStaticLoggerName(logName) != null)
                        {
                            return; // Log already initiated
                        }
                        else
                        {
                            logName = logName + DateTime.Now;
                        }
                    }
                }
                else
                {
                    if (loggerNameEnum != NCacheLog.LoggerNames.ClientLogs)
                    {
                        if (LoggingInformation.GetStaticLoggerName(logName) != null)
                        {
                            return; // Log already initiated
                        }
                        else
                        {
                            logName = logName + DateTime.Now;
                        }
                    }
                }

                filename = filename + "." +
                           Environment.MachineName.ToLower() + "." +
                           DateTime.Now.ToString("dd-MM-yy HH-mm-ss") + @".logs.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);

                    LoggingInformation.cacheLogger.Add(logName, logName);
                    if (loggerNameEnum != NCacheLog.LoggerNames.ClientLogs)
                    {
                        LoggingInformation.staticCacheLogger.Add(loggerNameEnum.ToString(), logName);
                    }

                    SetLevel(logName, NCacheLog.Level.OFF.ToString());
                    AddAppender(logName, CreateBufferAppender(logName, filepath));
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Пример #6
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");
            }
        }