예제 #1
0
 public static TraceAppender CreateTraceAppender()
 {
     var tracer = new TraceAppender { Layout = PatternLayout };
     tracer.ActivateOptions();
     PatternLayout.ActivateOptions();
     return tracer;
 }
예제 #2
0
        static Logger()
        {
            var hierarchy = (Hierarchy)LogManager.GetRepository();
            var tracer = new TraceAppender();
            var patternLayout = new PatternLayout {ConversionPattern = LOG_PATTERN};

            patternLayout.ActivateOptions();

            tracer.Layout = patternLayout;
            tracer.ActivateOptions();
            hierarchy.Root.AddAppender(tracer);

            var roller = new RollingFileAppender
                             {
                                 Layout = patternLayout,
                                 AppendToFile = true,
                                 RollingStyle = RollingFileAppender.RollingMode.Size,
                                 MaxSizeRollBackups = 4,
                                 MaximumFileSize = "10240KB",
                                 StaticLogFileName = true,
                                 File = FilePath + @"\f1speed-log.txt"
                             };
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            hierarchy.Root.Level = Level.Debug;
            hierarchy.Configured = true;
        }
예제 #3
0
파일: Logger.cs 프로젝트: dionata/wfmvc
        static Logger()
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
            TraceAppender tracer = new TraceAppender();
            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = LOG_PATTERN;
            patternLayout.ActivateOptions();

            tracer.Layout = patternLayout;
            tracer.ActivateOptions();
            hierarchy.Root.AddAppender(tracer);

            RollingFileAppender roller = new RollingFileAppender();
            roller.Layout = patternLayout;
            roller.AppendToFile = true;
            roller.RollingStyle = RollingFileAppender.RollingMode.Size;
            roller.MaxSizeRollBackups = 4;
            roller.MaximumFileSize = "32768KB";
            roller.StaticLogFileName = true;
            roller.File = "log\\Log.log";
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            hierarchy.Root.Level = Level.All;
            hierarchy.Configured = true;
        }
        /// <summary>
        /// Configures the log4net environment
        /// </summary>
        private void Setup(Level logLevel)
        {
            Directory.CreateDirectory(_logFolder);


            var hierarchy = (Hierarchy)LogManager.GetRepository();

            // Log to a file
            var roller = new RollingFileAppender();
            roller.AppendToFile = false;
            roller.File = _logFile;
            roller.Layout = new PatternLayout("%date %type.%method [%-5level] - %message%newline");
            roller.MaxSizeRollBackups = 5;
            roller.RollingStyle = RollingFileAppender.RollingMode.Size;
            roller.StaticLogFileName = true;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            // Log to the visual studio console
            var appender = new TraceAppender();
            appender.ActivateOptions();
            appender.Layout = new PatternLayout("%method (%line) %date [%-5level] - %message%newline");
            hierarchy.Root.AddAppender(appender);

            hierarchy.Root.Level = logLevel;
            hierarchy.Configured = true;
        }
예제 #5
0
        public DefaultLogWrapper(string logname, IConfig config)
        {
            this.logname = logname;

            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
            hierarchy.Clear();

            TraceAppender tracer = new TraceAppender();
            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = "%t (%-5level) - %m%n";
            patternLayout.ActivateOptions();

            tracer.Layout = patternLayout;
            tracer.ActivateOptions();
            hierarchy.Root.AddAppender(tracer);

            RollingFileAppender roller = new RollingFileAppender();
            roller.Layout = patternLayout;
            roller.AppendToFile = true;
            roller.RollingStyle = RollingFileAppender.RollingMode.Size;
            roller.MaxSizeRollBackups = 4;
            roller.MaximumFileSize = "100KB";
            roller.StaticLogFileName = true;
            roller.File = Path.Combine(config.IndexFolder, "totalrecall-" + this.logname + ".log");
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            hierarchy.Root.Level = Level.All;
            hierarchy.Configured = true;
        }
예제 #6
0
        public static void Configure(string appfolder, string logFile)
        {
            bool isConfigured = _log.Logger.Repository.Configured;

            if (!isConfigured)
            {
                // Setup RollingFileAppender
                var fileAppender = new RollingFileAppender
                {
                    Layout =
                        new PatternLayout(
                        "%d %level [%type{1}] - %m%n"),
                    MaximumFileSize = "1000KB",
                    MaxSizeRollBackups = 10,
                    RollingStyle = RollingFileAppender.RollingMode.Composite,
                    AppendToFile = true,
                    File = logFile,
                    ImmediateFlush = true,
                    LockingModel = new FileAppender.MinimalLock(),
                    Name = "XXXRollingFileAppender",
                    Threshold = log4net.Core.Level.All
                };
                fileAppender.ActivateOptions(); // IMPORTANT, creates the file
                BasicConfigurator.Configure(fileAppender);
            #if DEBUG
                // Setup TraceAppender
                TraceAppender ta = new TraceAppender();
                ta.Layout = new PatternLayout("%d [%t]%-5p %c [%x] - %m%n");
                BasicConfigurator.Configure(ta);
            #endif
            }
        }
        public void SetUpFixture()
        {
            Util.LogLog.InternalDebugging = true;

            Hierarchy hierarchy = (Hierarchy) LogManager.GetRepository();
            PatternLayout patternLayout = new PatternLayout { ConversionPattern = "%d [%t] %-5p %m%n" };

            patternLayout.ActivateOptions();

            TraceAppender tracer = new TraceAppender { Layout = patternLayout };

            tracer.ActivateOptions();

            hierarchy.Root.AddAppender(tracer);

            ConsoleAppender console = new ConsoleAppender
                                          {
                                              Name = "console",
                                              Layout = patternLayout,
                                              Target = "Console.Out",
                                              Threshold = Level.All,
                                          };

            console.ActivateOptions();

            hierarchy.Root.AddAppender(console);

            RollingFileAppender rollingFile = new RollingFileAppender
                                                  {
                                                      Name = "file",
                                                      Layout = patternLayout,
                                                      AppendToFile = true,
                                                      RollingStyle = RollingFileAppender.RollingMode.Size,
                                                      MaxSizeRollBackups = 4,
                                                      MaximumFileSize = "100KB",
                                                      StaticLogFileName = true,
                                                      LockingModel = new FileAppender.MinimalLock(),
                                                      File = "logs\\logFile.txt",
                                                  };

            rollingFile.ActivateOptions();

            hierarchy.Root.AddAppender(rollingFile);

            RollbarAppender rollbar = new RollbarAppender
                                          {
                                              Name = "rollbar",
                                              Layout = patternLayout,
                                              AccessToken = "3203880e148b43b4b1a14430fb41957a",
                                              Threshold = Level.Notice,
                                          };

            rollbar.ActivateOptions();

            hierarchy.Root.AddAppender(rollbar);

            hierarchy.Root.Level = Level.All;
            hierarchy.Configured = true;
        }
예제 #8
0
        static Log()
        {
            Config = LogConfigManager.Config;
            PatternLayout layout;
            AppenderSkeleton appender;

            switch (Config.Type)
            {
                case LogType.ConfigFromLogFile:
                    XmlConfigurator.ConfigureAndWatch(new FileInfo(Config.FileName));
                    break;
                case LogType.RollingFile:
                case LogType.RollingFileAndWinEventLog:
                    layout = new PatternLayout(Config.Pattern);
                    appender = new RollingFileAppender
                    {
                        File = Config.FileName,
                        AppendToFile = true,
                        RollingStyle = RollingFileAppender.RollingMode.Composite,
                        MaxSizeRollBackups = Config.MaxNumberOfBackupFiles,// App.Config.IsDebugConfiguration ? -1 : 100,
                        MaximumFileSize = Config.RollingFileMaximumFileSize,
                        DatePattern = Config.RollingFileDatePattern,
                        Layout = layout,
                        LockingModel = new FileAppender.MinimalLock()
                    };
                    layout.ActivateOptions();
                    appender.ActivateOptions();
                    BasicConfigurator.Configure(appender);
                    break;
                default:
                    if (Config.Type == LogType.WinEventLog ||
                        Config.Type == LogType.RollingFileAndWinEventLog)
                    {
                        layout = new PatternLayout(Config.Pattern);
                        appender = new EventLogAppender
                        {
                            LogName = App.Config.Name,
                            Layout = layout
                        };
                        layout.ActivateOptions();
                        appender.ActivateOptions();
                        BasicConfigurator.Configure(appender);
                    }
                    else if (Config.Type == LogType.VisualStudioTraceOutput)
                    {
                        layout = new PatternLayout(Config.Pattern);
                        appender = new TraceAppender
                        {
                            ImmediateFlush = true
                        };
                        layout.ActivateOptions();
                        appender.ActivateOptions();
                        appender.Layout = layout;
                        BasicConfigurator.Configure(appender);
                    }
                    break;
            }
        }
        /// <summary>
        /// Configures a trace appender for log4net so that log output 
        /// is written to the test output.
        /// </summary>
        public static void ConfigureLoggingToTrace() {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
            hierarchy.Root.RemoveAllAppenders();

            TraceAppender appender = new TraceAppender();
            PatternLayout patternLayout = new PatternLayout();
            patternLayout.ConversionPattern = "%d %-5p [%-10c]   %m%n%n";
            patternLayout.ActivateOptions();
            appender.Layout = patternLayout;
            appender.ActivateOptions();

            log4net.Config.BasicConfigurator.Configure(appender);
        }
예제 #10
0
        public AfterglowLogger(string applicationDataFolder, string loggingFile, int loggingLevel = LoggingLevels.LOG_LEVEL_ERROR)
        {
            string loggingPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), applicationDataFolder);
            if (!System.IO.Directory.Exists(loggingPath))
            {
                System.IO.Directory.CreateDirectory(loggingPath);
            }

            loggingPath = System.IO.Path.Combine(loggingPath, Path.GetDirectoryName(loggingFile));
            if (!System.IO.Directory.Exists(loggingPath))
            {
                System.IO.Directory.CreateDirectory(loggingPath);
            }
            
            string logFilePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), applicationDataFolder, loggingFile);

            _layout.ConversionPattern = DefaultPattern;
            _layout.ActivateOptions();
            
            _logger = LogManager.GetLogger(typeof(AfterglowLogger));

            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
            TraceAppender tracer = new TraceAppender();
            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = LOG_PATTERN;
            patternLayout.ActivateOptions();

            tracer.Layout = patternLayout;
            tracer.ActivateOptions();
            hierarchy.Root.AddAppender(tracer);

            RollingFileAppender roller = new RollingFileAppender();
            roller.Layout = patternLayout;
            roller.AppendToFile = true;
            roller.RollingStyle = RollingFileAppender.RollingMode.Size;
            roller.LockingModel = new log4net.Appender.FileAppender.MinimalLock();
            roller.MaxSizeRollBackups = 4;
            roller.MaximumFileSize = "100KB";
            roller.StaticLogFileName = true;
            roller.File = logFilePath;
            roller.Name = "RollingFileAppender";
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            LoggingLevel = loggingLevel;

            hierarchy.Configured = true;
        }
 internal static TraceAppender BuildTraceLog(ListeningLogOptions options)
 {
     var layout = new PatternLayout
     {
         ConversionPattern = options.Pattern
     };
     layout.ActivateOptions();
     var appender = new TraceAppender
     {
         Layout = layout,
         ImmediateFlush = options.ImmediateFlush
     };
     appender.ActivateOptions();
     return appender;
 }
예제 #12
0
 public static void InitLogger()
 {
     //NTT : let's configure log4net for coloredconsole output and debug trace
     //var layout = new log4net.Layout.SimpleLayout();
     //var layout = new log4net.Layout.PatternLayout("%-4timestamp [%thread] %-5level %logger %ndc - %message%newline");
     var layout = new log4net.Layout.PatternLayout("%date %-5level %message%newline");
     var ta = new TraceAppender { Layout = layout };
     var ca = new ColoredConsoleAppender { Threshold = Level.All, Layout = layout };
     var cca = new ColoredConsoleAppender { Threshold = Level.All, Layout = layout };
     cca.AddMapping(new ColoredConsoleAppender.LevelColors { Level = Level.Debug, ForeColor = ColoredConsoleAppender.Colors.Cyan | ColoredConsoleAppender.Colors.HighIntensity });
     cca.AddMapping(new ColoredConsoleAppender.LevelColors { Level = Level.Info, ForeColor = ColoredConsoleAppender.Colors.Green | ColoredConsoleAppender.Colors.HighIntensity });
     cca.AddMapping(new ColoredConsoleAppender.LevelColors { Level = Level.Warn, ForeColor = ColoredConsoleAppender.Colors.Purple | ColoredConsoleAppender.Colors.HighIntensity });
     cca.AddMapping(new ColoredConsoleAppender.LevelColors { Level = Level.Error, ForeColor = ColoredConsoleAppender.Colors.Red | ColoredConsoleAppender.Colors.HighIntensity });
     cca.AddMapping(new ColoredConsoleAppender.LevelColors { Level = Level.Fatal, ForeColor = ColoredConsoleAppender.Colors.White | ColoredConsoleAppender.Colors.HighIntensity, BackColor = ColoredConsoleAppender.Colors.Red });
     cca.ActivateOptions();
     BasicConfigurator.Configure(cca);
     Logger l = (Logger)log.Logger;
     l.AddAppender(ta);
 }
예제 #13
0
        public void DefaultCategoryTest()
        {
            CategoryTraceListener categoryTraceListener = new CategoryTraceListener();
            Trace.Listeners.Clear();
            Trace.Listeners.Add(categoryTraceListener);

            ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());

            TraceAppender traceAppender = new TraceAppender();
            traceAppender.Layout = new SimpleLayout();
            traceAppender.ActivateOptions();

            BasicConfigurator.Configure(rep, traceAppender);

            ILog log = LogManager.GetLogger(rep.Name, GetType());
            log.Debug("Message");

            Assert.AreEqual(
                GetType().ToString(),
                categoryTraceListener.Category);
        }
예제 #14
0
        private static void StartLogSimulator()
        {
            var traceAppender = new TraceAppender { Layout = new PatternLayout() };

            var udpAppender = new UdpAppender
            {
                RemoteAddress = IPAddress.Loopback,
                RemotePort = 8080,
                Name = "UDPAppender",
                Encoding = new ASCIIEncoding(),
                Threshold = Level.Debug,
                Layout = new XmlLayoutSchemaLog4j()
            };
            udpAppender.ActivateOptions();

            BasicConfigurator.Configure(traceAppender, udpAppender);

            var log = LogManager.GetLogger("Simulator");
            log4net.GlobalContext.Properties["ApplicationId"] = "log4stuff";

            var rand = new Random();
            SimulatorTimer = new Timer(state =>
            {
                var option = rand.Next(0, 3); //max is exclusive
                switch (option)
                {
                    case 0:
                        log.Info("This is an info message");
                        break;
                    case 1:
                        log.Debug("This is a really long message that will be truncated. It would never fit into a single row.");
                        break;
                    default:
                        log.Debug("This is a debug message");
                        break;
                }

            }, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));

        }
예제 #15
0
        private static void CreateRepository(string appName, string repositoryName)
        {
            var repository = LoggerManager.CreateRepository(repositoryName);
            var hierarchy = (Hierarchy) repository;
            var tracer = new TraceAppender();
            var patternLayout = new PatternLayout
            {
                ConversionPattern = LogPattern
            };

            patternLayout.ActivateOptions();

            tracer.Layout = patternLayout;
            tracer.ActivateOptions();
            hierarchy.Root.AddAppender(tracer);

            var logFileCommonFolder = Path.Combine(Functions.GetAppDataDirectory(appName), "logs");
            var logFileFolder = Path.Combine(logFileCommonFolder, repositoryName);
            var logFileName = Path.Combine(logFileFolder, "logfile_.txt");

            var roller = new RollingFileAppender
            {
                Layout = patternLayout,
                AppendToFile = true,
                RollingStyle = RollingFileAppender.RollingMode.Date,
                MaxSizeRollBackups = -1,
                DatePattern = "yyyy.MM.dd",
                StaticLogFileName = false,
                File = logFileName,
                PreserveLogFileNameExtension = true
            };
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            hierarchy.Root.Level = Level.All;
            hierarchy.Configured = true;
        }
예제 #16
0
        public void MethodNameCategoryTest()
        {
            CategoryTraceListener categoryTraceListener = new CategoryTraceListener();
            Trace.Listeners.Clear();
            Trace.Listeners.Add(categoryTraceListener);

            ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());

            TraceAppender traceAppender = new TraceAppender();
            PatternLayout methodLayout = new PatternLayout("%method");
            methodLayout.ActivateOptions();
            traceAppender.Category = methodLayout;
            traceAppender.Layout = new SimpleLayout();
            traceAppender.ActivateOptions();

            BasicConfigurator.Configure(rep, traceAppender);

            ILog log = LogManager.GetLogger(rep.Name, GetType());
            log.Debug("Message");

            Assert.AreEqual(
                System.Reflection.MethodInfo.GetCurrentMethod().Name,
                categoryTraceListener.Category);
        }
예제 #17
0
        public void Init()
        {
            var layout = new PatternLayout("%utcdate %-5level - %message%newline");
            layout.ActivateOptions();

            var appender = new Log4NetAppender
                {
                    Layout = layout,
                    Server = TestSettings.Instance.MetricsLoggingUrl,
                    AccessKey = TestSettings.Instance.AccessKey,
                    ApplicationKey = AppKey,
                };
            appender.ActivateOptions();

            _tracker = appender.Tracker;

            var appender2 = new TraceAppender
                {
                    Layout = layout,
                };

            BasicConfigurator.Configure(appender);
            BasicConfigurator.Configure(appender2);
        }
예제 #18
0
파일: Logger.cs 프로젝트: jardrake03/incert
        static Logger()
        {
            ThreadContext.Properties["Identifier"] = Application.Current.GetIdentifier();
            ThreadContext.Properties["UserId"] = "[Unknown]";
            ThreadContext.Properties["Session"] = Application.Current.GetSessionId();

            var hiearchy = (Hierarchy)LogManager.GetRepository();

            var patternLayout = new PatternLayout { ConversionPattern = LogPattern };
            patternLayout.ActivateOptions();

            var tracer = new TraceAppender {Layout = patternLayout};
            tracer.ActivateOptions();
            hiearchy.Root.AddAppender(tracer);

            var roller = new RollingFileAppender
                {
                    Layout = patternLayout,
                    AppendToFile = true,
                    RollingStyle = RollingFileAppender.RollingMode.Once,
                    MaxSizeRollBackups = -1,
                    MaximumFileSize = "100KB",
                    StaticLogFileName = false,
                    File = PathUtilities.LogFile,
                    Threshold = Level.Debug,
                    LockingModel = new FileAppender.MinimalLock()
                };

            roller.ActivateOptions();
            roller.RollingStyle = RollingFileAppender.RollingMode.Once;
            roller.LockingModel = new FileAppender.MinimalLock();
            hiearchy.Root.AddAppender(roller);

            hiearchy.Root.Level = Level.Debug;
            hiearchy.Configured = true;
        }
예제 #19
0
        protected override void Configure(TestConfiguration config, Random random)
        {
            base.Configure(config, random);

            var tracer = new TraceAppender();
            var hierarchy = (Hierarchy)LogManager.GetRepository();

            var patternLayout = new PatternLayout { ConversionPattern = "%property{log4net:HostName}" };
            tracer.Layout = patternLayout;

            hierarchy.Root.AddAppender(tracer);
            hierarchy.Configured = true;

            Log = LogManager.GetLogger("");
        }
예제 #20
0
        /// <summary>
        ///    Utility function to initialize logging.  This will check for a log configuration file
        ///    and use that to configure the logging.  If the log configuration file is not available,
        ///    this method will check the default log configuration file.  If that file is not 
        ///    available either, this method will create a primitive configuration that writes logs to
        ///    the filename specified as the defaultLogfileName
        /// </summary>
        /// <param name="configFilename">the path (can be relative) to the log config file</param>
        /// <param name="defaultConfigFilename">the path (can be relative) to the default log config file</param>
        /// <param name="defaultLogfileName">the filename to use for logging if the config files are not found</param>
        public static void InitializeLogging(string configFilename, string defaultConfigFilename, string defaultLogfileName, bool interactive)
        {
            if (File.Exists(configFilename))
            {
                XmlConfigurator.ConfigureAndWatch(new FileInfo(configFilename));
            }
            else if (File.Exists(defaultConfigFilename))
            {
                XmlConfigurator.ConfigureAndWatch(new FileInfo(defaultConfigFilename));
            }
            else
            {
                // should only get here if someone has a messed up install

                if (interactive)
                {
                    RollingFileAppender rfa = new RollingFileAppender();
                    rfa.Layout = new PatternLayout("%-5p [%d{ISO8601}] %-20.20c{1} %m%n");
                    rfa.File = defaultLogfileName;
                    rfa.AppendToFile = false;
                    rfa.MaximumFileSize = "5MB";
                    rfa.MaxSizeRollBackups = 2;
                    rfa.RollingStyle = RollingFileAppender.RollingMode.Once;
                    rfa.ActivateOptions();
                    BasicConfigurator.Configure(rfa);
                    SetLogLevel(log4net.Core.Level.Info, true);
                }
                else
                {
                    // use the trace appender if we are not running interactive
                    TraceAppender ta = new TraceAppender();
                    ta.Layout = new PatternLayout("%-5p [%d{ISO8601}] %-20.20c{1} %m%n");
                    ta.ActivateOptions();
                    BasicConfigurator.Configure(ta);
                    SetLogLevel(log4net.Core.Level.Info, true);
                }

                logUtilLog.Info("Unable to find logging config files.  Using fallback simple logging configuration.");
                logUtilLog.InfoFormat("Logging config file: {0}", configFilename);
            }
        }
예제 #21
0
        private static void EnsureLoggerInited()
        {
            #region Log4Net remove because just supports sync logging.
            var hierarchy = (Hierarchy)LogManager.GetRepository();
            if (hierarchy.Exists(NAME) != null) return;

            var patternLayout = new PatternLayout { ConversionPattern = "%date [%level] [%thread] %logger - %message%newline" };
            patternLayout.ActivateOptions();

            //var appender = new RollingFileAppender
            //{
            //	AppendToFile = true,
            //	File = @"C:\log\kart\",
            //	DatePattern = @"yyyyMMdd\all_yyyyMMdd'.log'",
            //	Layout = patternLayout,
            //	MaxSizeRollBackups = 5,
            //	MaximumFileSize = "1GB",
            //	RollingStyle = RollingFileAppender.RollingMode.Date,
            //	StaticLogFileName = false
            //};
            //appender.ActivateOptions();
            //hierarchy.Root.AddAppender(appender);

            var memory = new TraceAppender() { Name = NAME, Layout = patternLayout };
            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            //var eventStreamAppender = new EventStreamAppender() { Name = NAME };
            //hierarchy.Root.AddAppender(eventStreamAppender);

            hierarchy.Root.Level = Level.All;
            hierarchy.Configured = true;

            log4net.Config.BasicConfigurator.Configure(hierarchy);
            #endregion
        }
예제 #22
0
        private void SetupLogger()
        {
            var defaultAppender = new TraceAppender
                {
                    Layout = new SimpleLayout(),
                    Threshold = Level.Warn
                };

            BasicConfigurator.Configure(defaultAppender);

            var mobiLogger = (Logger) LogManager.GetLogger("MobiCentric").Logger;

            var mobiAppender = new TraceAppender
                {
                    Layout = new SimpleLayout(),
                    Threshold = Level.All,
                };

            mobiLogger.AddAppender(mobiAppender);
        }
 // Configure the file logger programmatically.
 public static void ConfigureFileAppender(ILog log, string logDirPath, Level level)
 {
     bool isConfigured = log.Logger.Repository.GetAppenders().OfType<RollingFileAppender>().Any();
     if (!isConfigured)
     {
         // Setup RollingFileAppender
         RollingFileAppender appender = new RollingFileAppender();
         appender.Layout = new log4net.Layout.PatternLayout(DefaultLayoutPattern);
         appender.MaximumFileSize = "10MB";
         appender.MaxSizeRollBackups = 5;
         appender.RollingStyle = RollingFileAppender.RollingMode.Composite;
         appender.AppendToFile = true;
         // The log path must be specified with a backslash for log4net to detect this as the log directory and not the
         // log file name.
         appender.File = logDirPath[logDirPath.Length - 1] == '\\' ? logDirPath : logDirPath + '\\';
         appender.Name = "RollingFileAppender";
         appender.Threshold = level;
         appender.StaticLogFileName = false;
         appender.DatePattern = String.Format("'{0}'yyyyMMdd'.log'", log.Logger.Name);
         appender.ActivateOptions(); // IMPORTANT, creates the file
         BasicConfigurator.Configure(appender);
         log.Info("Name: " + log.Logger.Name);
     #if DEBUG
         // Setup TraceAppender
         TraceAppender ta = new TraceAppender();
         ta.Layout = new log4net.Layout.PatternLayout(DefaultLayoutPattern);
         BasicConfigurator.Configure(ta);
     #endif
     }
 }
예제 #24
0
        public static void Initialize(string logDir, string fileName, string category)
        {
            _logFile = System.IO.Path.Combine(logDir, fileName);

            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
            TraceAppender tracer = new TraceAppender();
            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = LOG_PATTERN;
            patternLayout.ActivateOptions();

            tracer.Layout = patternLayout;
            tracer.ActivateOptions();
            hierarchy.Root.AddAppender(tracer);

            RollingFileAppender roller = new RollingFileAppender();
            roller.Layout = patternLayout;
            roller.AppendToFile = true;
            roller.RollingStyle = RollingFileAppender.RollingMode.Size;
            roller.MaxSizeRollBackups = 4;
            roller.MaximumFileSize = "100KB";
            roller.StaticLogFileName = true;
            roller.File = _logFile;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            hierarchy.Root.Level = Level.All;
            hierarchy.Configured = true;

            _log = log4net.LogManager.GetLogger(category);
        }
예제 #25
0
            private static IAppender CreateTraceAppender(string logName)
            {
                TraceAppender appender = new TraceAppender();
                appender.Layout = CreateTraceLayout();

                return appender;
            }