Beispiel #1
0
        public void AddAppender(string appenderName, ILogger wLogger)
        {
            if (!ConfigurationManager.AppSettings.AllKeys.Contains("BackupPath"))
            {
                throw new Exception("Parameter 'BackupPath' is mandatory");
            }

            string filename = ConfigurationManager.AppSettings["BackupPath"].ToString() + "\\" + appenderName + ".sql";

            log4net.Repository.Hierarchy.Logger l = (log4net.Repository.Hierarchy.Logger)wLogger;

            log4net.Appender.IAppender hasAppender = l.GetAppender(appenderName);
            if (hasAppender == null)
            {
                log4net.Appender.RollingFileAppender appender = new log4net.Appender.RollingFileAppender();
                appender.DatePattern       = "yyyyMMdd";
                appender.RollingStyle      = log4net.Appender.RollingFileAppender.RollingMode.Date;
                appender.AppendToFile      = true;
                appender.File              = filename;
                appender.StaticLogFileName = true;
                appender.Name              = appenderName;

                log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout();
                layout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
                layout.ActivateOptions();

                appender.Layout = layout;
                appender.ActivateOptions();

                l.AddAppender(appender);
            }
        }
Beispiel #2
0
        /// <summary>
        /// This method creates the loggers
        /// </summary>
        /// <param name="fileAppender"></param>
        /// <param name="loggerName"></param>
        private void CreateLogger(log4net.Appender.FileAppender fileAppender, string loggerName)
        {
            log4net.Repository.Hierarchy.Hierarchy hierarchy = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository();
            log4net.Repository.Hierarchy.Logger    logger    = (log4net.Repository.Hierarchy.Logger)hierarchy.GetLogger(loggerName);
            if (logger.GetAppender(fileAppender.Name) == null)
            {
                logger.AddAppender(fileAppender);
            }

            hierarchy.Configured = true;
        }
Beispiel #3
0
        public static void AddAppender2(ILog log, IAppender appender)
        {
            log4net.Repository.Hierarchy.Logger l = (log4net.Repository.Hierarchy.Logger)log.Logger;

            if (l.GetAppender(appender.Name) != null)
            {
                return;
            }

            l.Additivity = false;
            l.AddAppender(appender);
        }
Beispiel #4
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);
        }
        private static void ShutdownStartupLogAppender(log4netLogger logger)
        {
            var startupAppender = logger.GetAppender(STARTUP_APPENDER_NAME) as MemoryAppender;

            if (startupAppender != null)
            {
                LoggingEvent[] events = startupAppender.GetEvents();
                logger.RemoveAppender(startupAppender);

                if (events != null)
                {
                    foreach (LoggingEvent logEvent in events)
                    {
                        logger.Log(logEvent.Level, logEvent.MessageObject, null);
                    }
                }
            }
        }
Beispiel #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="user"></param>
        /// <param name="collectionId"></param>
        public SimiasAccessLogger(string user, string collectionId)
        {
            this.user         = user;
            this.collectionId = collectionId;
            logger            = LogManager.GetLogger(AccessLoggerName);

            lock (typeof(SimiasAccessLogger))
            {
                if (FormatString == null)
                {
                    try
                    {
                        log4net.Repository.Hierarchy.Logger ll = logger.Logger as log4net.Repository.Hierarchy.Logger;
                        string   header  = ((log4net.Appender.AppenderSkeleton)ll.GetAppender("AccessLogFile")).Layout.Header;
                        string[] headers = header.Split('\n');
                        foreach (string line in headers)
                        {
                            if (line.StartsWith("#Fields:"))
                            {
                                Fields = line.ToLower();
                                string [] fields = Fields.Split("**".ToCharArray());

                                // Now create the format string.
                                StringBuilder sb = new StringBuilder(512);
                                foreach (string field in fields)
                                {
                                    switch (field)
                                    {
                                    case "date":
                                        sb.Append("{5}\t");
                                        break;

                                    case "time":
                                        sb.Append("{6}\t");
                                        break;

                                    case "user":
                                        sb.Append("\"{0}\"\t");
                                        break;

                                    case "method":
                                        sb.Append("\"{1}\"\t");
                                        break;

                                    case "uri":
                                        sb.Append("\"{2}\"\t");
                                        break;

                                    case "id":
                                        sb.Append("\"{3}\"\t");
                                        break;

                                    case "status":
                                        sb.Append("\"{4}\"\t");
                                        break;

                                    default:
                                        break;
                                    }
                                }
                                FormatString = sb.ToString();
                                break;
                            }
                        }
                    }
                    catch
                    {
                        FormatString = "{5}\t{4}\t\"{0}\"\t\"{1}\"\t\"{2}\"\t\"{3}\"";
                    }
                }
            }
        }