/// <summary>
        /// </summary>
        [Test] public void TestSetupAppender()
        {
            SetupRepository();

            Assert.AreEqual(0, m_countingAppender.Counter, "Test empty appender");

            ILogger logger = m_hierarchy.GetLogger("test");

            logger.Log(typeof(BufferingAppenderTest), Level.Warn, "Message logged", null);

            Assert.AreEqual(1, m_countingAppender.Counter, "Test 1 event logged");
        }
示例#2
0
        static Logger()
        {
            //
            // TODO: Add constructor logic here
            //
            Trace.WriteLine("Logger contructor");

            connstring = ConfigurationManager.ConnectionStrings["SqlConn"].ConnectionString;
            if (connstring.Length == 0)
            {
                Trace.WriteLine("Errore impostazione connection string DB LOG", LoggerName);
                return;
            }


            log4net.Config.XmlConfigurator.Configure();

            log4net.Repository.Hierarchy.Hierarchy hier =
                log4net.LogManager.GetRepository() as log4net.Repository.Hierarchy.Hierarchy;

            if (hier != null)
            {
                //get ADONetAppender
                log4net.Appender.AdoNetAppender adoAppender =
                    (log4net.Appender.AdoNetAppender)hier.GetLogger(LoggerName,
                                                                    hier.LoggerFactory).GetAppender("AdoNetAppender");
                if (adoAppender != null)
                {
                    adoAppender.ConnectionString =
                        connstring;
                    adoAppender.ActivateOptions(); //refresh settings of appender
                }
            }

            log_level = ConfigurationManager.AppSettings["log_level"] + "";

            try
            {
                DefaultLogLevel = (EventLogEntryType)Enum.Parse(typeof(EventLogEntryType), log_level, true);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString(), LoggerName);
            }

            cs = (ConfigurationManager.AppSettings["log_cat"] + string.Empty);
        }
示例#3
0
        private static ILog GetInstance()
        {
            if (log == null)
            {
                log = log4net.LogManager.GetLogger("LogHelper");

                log4net.Repository.Hierarchy.Hierarchy h = LogManager.GetRepository() as log4net.Repository.Hierarchy.Hierarchy;

                if (h != null)
                {
                    log4net.Appender.RollingFileAppender appender = (log4net.Appender.RollingFileAppender)h.GetLogger("LogHelper", h.LoggerFactory).GetAppender("RollingFileAppender");

                    if (appender != null)
                    {
                        string filePath = string.Format(System.Configuration.ConfigurationManager.AppSettings["LogFile"], DateTime.Now.ToString("yyyy.MM.dd.HH.mm.ss") + ".log");
                        appender.File = filePath;
                        appender.ActivateOptions();
                        LogFilePath = appender.File;
                    }
                }
            }

            return(log);
        }
示例#4
0
        /// <summary>
        /// Configure the log4net
        /// </summary>
        ///  <example>
        /// An example of a logger name = MyApplication
        /// /// </example>
        public static void Configure(string logger, string configFile, LogType type, string appernder)
        {
            logType = type;
            //Gets the logger object
            log = LogManager.GetLogger(logger);

            if (configFile != null && configFile.Length != 0)
            {
                FileInfo fInfo = null;
                try
                {
                    fInfo = new FileInfo(System.Web.HttpRuntime.AppDomainAppPath + @"bin\" + configFile);
                }
                catch
                {
                    fInfo = new FileInfo(@".\" + configFile);
                }

                //Configure the log4net by reading config file
                log4net.Config.XmlConfigurator.Configure(fInfo);
            }
            else
            {
                log4net.Config.XmlConfigurator.Configure();
            }

            //if there is AdoNetAppender, decrypt the connection
            log4net.Repository.Hierarchy.Hierarchy h = LogManager.GetRepository() as log4net.Repository.Hierarchy.Hierarchy;
            if (h != null)
            {
                log4net.Appender.AdoNetAppender adoAppender = (log4net.Appender.AdoNetAppender)h.GetLogger("logger.database", h.LoggerFactory).GetAppender(appernder);
                if (adoAppender != null)
                {
                    EncryptUtility de = new EncryptUtility(EncryptUtility.SymmProvEnum.DES);
                    adoAppender.ConnectionString = de.Decrypting(adoAppender.ConnectionString, ENCRYPTION_KEY);
                    adoAppender.ActivateOptions();
                }
            }
        }
示例#5
0
文件: UtilLog.cs 项目: zxlnet/hrms
        /// <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;
        }