Example #1
0
        /// <summary>
        /// Add a desired appender to the logger
        /// </summary>
        /// <param name="loggerName">Name of the logger to which the appender is to be added</param>
        /// <param name="appender">Appender to add to the logger</param>
        private static void AddAppender(string loggerName, log4net.Appender.IAppender appender)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(loggerName);
            log4net.Repository.Hierarchy.Logger l = (log4net.Repository.Hierarchy.Logger)log.Logger;

            l.AddAppender(appender);
        }
Example #2
0
        /// <summary>
        /// Add a desired appender to the logger
        /// </summary>
        /// <param name="loggerName">Name of the logger to which the appender is to be added</param>
        /// <param name="appender">Appender to add to the logger</param>
        private void AddAppender(log4net.Appender.IAppender appender)
        {
            log = log4net.LogManager.GetLogger(_loggerName);
            log4net.Repository.Hierarchy.Logger l = (log4net.Repository.Hierarchy.Logger)log.Logger;

            l.AddAppender(appender);
        }
        // Add an appender to a logger
        public static void AddAppender(string loggerName, log4net.Appender.IAppender appender)
        {
            log4net.ILog log = LogManager.GetLogger(loggerName);
            var          l   = (Logger)log.Logger;

            l.AddAppender(appender);
        }
Example #4
0
        public static ILog GetLog(string logName = "")
        {
            ILog log = null;

            if (string.IsNullOrEmpty(logName))
            {
                log = s_Log;
                return(log);
            }

            if (s_DTName2Log.ContainsKey(logName))
            {
                log = LogManager.GetLogger(logName);
                return(log);
            }

            var hierarchy = (Hierarchy)LogManager.GetRepository();
            // var logger = hierarchy.LoggerFactory.CreateLogger((ILoggerRepository)hierarchy, logName);
            var logger = (Logger)LogManager.GetLogger(logName).Logger;

            logger.Hierarchy = hierarchy;
            log4net.Appender.IAppender fileAppender = CreateFileAppender(s_Appenders[0], logName);

            logger.AddAppender(fileAppender);

            logger.Repository.Configured = true;
            hierarchy.Threshold          = logger.Level = ((Logger)s_Log.Logger).Level;

            s_DTName2Log.Add(logName, logger);

            // log = new LogImpl(logger);
            log = LogManager.GetLogger(logName);
            return(log);
        }
Example #5
0
        //public static void AddAppender(string appenderName, ILogger wLogger)
        //{
        //    log4net.Repository.Hierarchy.Logger l = (log4net.Repository.Hierarchy.Logger)wLogger;

        //    log4net.Appender.IAppender hasAppender = l.GetAppender(appenderName);
        //    if (hasAppender != null)
        //    {
        //        hasAppender..ActivateOptions();

        //        l.AddAppender(hasAppender);
        //    }
        //}

        public static void AddAppender(string appenderName, ILogger wLogger)
        {
            string filename = ConfigurationManager.AppSettings["LogDir"].ToString() + "\\" + appenderName + ".log";

            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);
            }
        }
Example #6
0
 // Add an appender to a logger
 public static void AddAppender(string loggerName, log4net.Appender.IAppender appender)
 {
     try
     {
         log4net.ILog log = log4net.LogManager.GetLogger(loggerName);
         log4net.Repository.Hierarchy.Logger l = (log4net.Repository.Hierarchy.Logger)log.Logger;
         l.AddAppender(appender);
     }
     catch (Exception er)
     {
         using (StreamWriter sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\FatalLogError.log", true))
         {
             sw.WriteLine(er.Message);
         }
     }
 }
Example #7
0
        public static ILog GetLogger(Type tBaseType, string levelName)
        {
            if (_logg == null)
            {
                _logg = new Instance();
            }

            ILog logResult = null;

            try
            {
                string strTypeName = tBaseType.FullName;
                log4net.Appender.IAppender[] objAppenders = log4net.LogManager.GetRepository().GetAppenders();
                bool blFound = false;
                if (objAppenders.Length > 0)
                {
                    for (int i = 0; i < objAppenders.Length; i++)
                    {
                        log4net.Appender.IAppender objA = objAppenders[i];
                        if (strTypeName + T1.Log.Settings._Main.appenderSufix == objA.Name)
                        {
                            blFound = true;
                            break;
                        }
                    }
                }
                if (blFound)
                {
                    logResult = LogManager.GetLogger(strTypeName);
                }
                else
                {
                    SetLevel(strTypeName, levelName);
                    AddAppender(strTypeName, CreateFileAppender(strTypeName, strTypeName, levelName));
                    logResult = LogManager.GetLogger(strTypeName);
                }
            }
            catch (Exception er)
            {
                using (StreamWriter sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\FatalLogError.log", true))
                {
                    sw.WriteLine(er.Message);
                }
            }
            return(logResult);
        }
Example #8
0
        public static ILog GetLogger(Type tBaseType, string levelName)
        {
            if (_logg == null)
            {
                _logg = new Instance();
            }
            ILog   logResult   = null;
            string strTypeName = tBaseType.FullName;

            log4net.Appender.IAppender[] objAppenders = log4net.LogManager.GetRepository().GetAppenders();
            bool blFound = false;

            if (objAppenders.Length > 0)
            {
                for (int i = 0; i < objAppenders.Length; i++)
                {
                    log4net.Appender.IAppender objA = objAppenders[i];
                    if (strTypeName + Settings._Main.appenderSufix == objA.Name)
                    {
                        blFound = true;
                        break;
                    }
                }
            }
            if (blFound)
            {
                logResult = LogManager.GetLogger(strTypeName);
            }
            else
            {
                SetLevel(strTypeName, levelName);
                AddAppender(strTypeName, CreateFileAppender(strTypeName, strTypeName, levelName));
                logResult = LogManager.GetLogger(strTypeName);
            }
            return(logResult);
        }
Example #9
0
        public static void AddAppenderToRoot(log4net.Appender.IAppender appender)
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            hierarchy.Root.AddAppender(appender);
        }