Пример #1
0
        private static void SetupLog()
        {
            if (Alma.Common.Config.Settings.Logging.Enable)
            {
                var hierarchy = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository(System.Reflection.Assembly.GetExecutingAssembly());
                // Remove any other appenders
                hierarchy.Root.RemoveAllAppenders();
                // define some basic settings for the root
                var rootLogger = hierarchy.Root;
                rootLogger.Level = log4net.Core.Level.Error;


                // This is required, so that we can access the Logger by using
                // LogManager.GetLogger("NHibernate.SQL") and it can used by NHibernate
                var loggerNH = hierarchy.GetLogger("NHibernate.SQL") as log4net.Repository.Hierarchy.Logger;
                loggerNH.Level = log4net.Core.Level.Debug;
                loggerNH.RemoveAllAppenders();

                // declare a TraceAppender with 5MB per file and max. 10 files
                var pattern = new log4net.Layout.PatternLayout("%message%newline");
                pattern.Header = "";
                var appender = new log4net.Appender.TraceAppender();
                appender.Layout = pattern;
                loggerNH.AddAppender(appender);



                // this is required to tell log4net that we're done
                // with the configuration, so the logging can start
                hierarchy.Configured = true;
                log4net.Config.BasicConfigurator.Configure(hierarchy);
            }
        }
Пример #2
0
 /// <summary>
 /// Method is to be used by unit tests to get TraceLogging.
 /// </summary>
 public static void ConfigureForUnitTesting()
 {
     log4net.Appender.TraceAppender traceAppender = new log4net.Appender.TraceAppender();
     traceAppender.Layout         = new log4net.Layout.PatternLayout("%d [%t] %-5p %c [%x] - %m%n");
     traceAppender.ImmediateFlush = true;
     log4net.Config.BasicConfigurator.Configure(traceAppender);
 }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        public static void InitLog4Net()
        {
            var hierarchy = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository();

            hierarchy.Configured = true;

            var rollingAppender = new log4net.Appender.RollingFileAppender
            {
                File = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\" +
                       string.Format("{0:yyyy-MM-dd}", DateTime.Now) + ".log",
                AppendToFile = true,
                RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Date,
                LockingModel = new log4net.Appender.FileAppender.MinimalLock(),
                DatePattern  = "_yyyyMMdd-hh\".log\"",

                Layout = new log4net.Layout.PatternLayout("[%thread] %level %logger - %message [Extra Info: %property{testProperty} %exception]%n")
            };

            var traceAppender = new log4net.Appender.TraceAppender()
            {
                Layout = new log4net.Layout.PatternLayout("[%thread] %level %logger - %message [Extra Info: %property{testProperty} %exception]%n")
            };

            hierarchy.Root.AddAppender(rollingAppender);
            hierarchy.Root.AddAppender(traceAppender);
            rollingAppender.ActivateOptions();

            hierarchy.Root.Level = log4net.Core.Level.All;
        }
Пример #4
0
        /// <summary>
        /// 
        /// </summary>
        public static void InitLog4Net()
        {
            var hierarchy = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository();

            hierarchy.Configured = true;

            var rollingAppender = new log4net.Appender.RollingFileAppender
            {
                File = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\" +
                string.Format("{0:yyyy-MM-dd}", DateTime.Now) + ".log",
                AppendToFile = true,
                RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Date,
                LockingModel = new log4net.Appender.FileAppender.MinimalLock(),
                DatePattern = "_yyyyMMdd-hh\".log\"",
              
                Layout = new log4net.Layout.PatternLayout("[%thread] %level %logger - %message [Extra Info: %property{testProperty} %exception]%n")
            };

            var traceAppender = new log4net.Appender.TraceAppender()
            {
                Layout = new log4net.Layout.PatternLayout("[%thread] %level %logger - %message [Extra Info: %property{testProperty} %exception]%n")
            };

            hierarchy.Root.AddAppender(rollingAppender);
            hierarchy.Root.AddAppender(traceAppender);
            rollingAppender.ActivateOptions();

            hierarchy.Root.Level = log4net.Core.Level.All;  
        }
Пример #5
0
 /// <summary>
 /// Method is to be used by unit tests to get TraceLogging.  If log4net configuration file
 ///	is not found, this method is called internally to enable logging to trace by default.
 /// </summary>
 public static void ConfigureForUnitTesting()
 {
     if (!_unitTestingConfigured)
     {
         _unitTestingConfigured = true;
         log4net.Appender.TraceAppender traceAppender = new log4net.Appender.TraceAppender();
         traceAppender.Layout         = new log4net.Layout.PatternLayout("%date %-5level - %message%newline");
         traceAppender.ImmediateFlush = true;
         log4net.Config.BasicConfigurator.Configure(traceAppender);
     }
 }
Пример #6
0
        private static log4net.Appender.TraceAppender GetTraceAppender(
            log4net.Core.Level traceLogLevel)
        {
            log4net.Appender.TraceAppender appender = new log4net.Appender.TraceAppender();
            appender.Name   = "Trace";
            appender.Layout = new log4net.Layout.PatternLayout(
                "%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p %c - %m%n");
            appender.Threshold = traceLogLevel;
            appender.ActivateOptions();

            return(appender);
        }
Пример #7
0
 public void Setup()
 {
     log4net.Appender.TraceAppender appender = new log4net.Appender.TraceAppender();
     appender.Layout = new log4net.Layout.PatternLayout("%message");
     log4net.Config.BasicConfigurator.Configure();
 }
Пример #8
0
 public static void ConfigureForUnitTesting()
 {
     log4net.Appender.TraceAppender appender = new log4net.Appender.TraceAppender();
     appender.Layout = new log4net.Layout.PatternLayout("%date [%thread] %-5level %logger [%property{NDC}] - %message%newline");
     log4net.Config.BasicConfigurator.Configure(appender);
 }
Пример #9
0
 /// <summary>
 /// Method is to be used by unit tests to get TraceLogging.
 /// </summary>
 public static void ConfigureForUnitTesting()
 {
     log4net.Appender.TraceAppender traceAppender = new log4net.Appender.TraceAppender();
     traceAppender.Layout = new log4net.Layout.PatternLayout("%d [%t] %-5p %c [%x] - %m%n");
     traceAppender.ImmediateFlush = true;
     log4net.Config.BasicConfigurator.Configure(traceAppender);
 }
Пример #10
0
 /// <summary>
 /// Method is used to configure the logging framework 
 /// to write to trace. This will be picked up by nunit.
 /// </summary>
 public static void ConfigureForUnitTesting()
 {
     log4net.Appender.TraceAppender appender = new log4net.Appender.TraceAppender();
     appender.Layout = new log4net.Layout.PatternLayout(LAYOUTFORMAT);
     log4net.Config.BasicConfigurator.Configure(appender);
 }
Пример #11
0
        private static log4net.Appender.TraceAppender GetTraceAppender(
            log4net.Core.Level traceLogLevel)
        {
            log4net.Appender.TraceAppender appender = new log4net.Appender.TraceAppender();
            appender.Name = "Trace";
            appender.Layout = new log4net.Layout.PatternLayout(
                "%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p %c - %m%n");
            appender.Threshold = traceLogLevel;
            appender.ActivateOptions();

            return appender;
        }