Beispiel #1
0
        public CustomLogger(string path, string prefix, Level minLevel, Level maxLevel)
        {
            this.string_0 = prefix;
            this.level_0  = minLevel ?? Level.All;
            this.level_1  = maxLevel ?? Level.Emergency;
            Directory.CreateDirectory(path);
            PatternLayout layout = new PatternLayout("%-4utcdate [%thread] %-5level %logger{1} %ndc - %message%newline");
            DateTime      now    = DateTime.Now;

            this.FileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), string.Format(@"{6}\{7} {5} {0:0000}-{1:00}-{2:00} {3:00}.{4:00}.txt", new object[] { now.Year, now.Month, now.Day, now.Hour, now.Minute, Process.GetCurrentProcess().Id, path, this.string_0 }));
            FileAppender appender1 = new FileAppender
            {
                File         = this.FileName,
                Layout       = layout,
                LockingModel = new FileAppender.MinimalLock()
            };
            FileAppender     newAppender = appender1;
            LevelRangeFilter filter      = new LevelRangeFilter
            {
                LevelMin      = this.level_0,
                LevelMax      = this.level_1,
                AcceptOnMatch = true
            };

            newAppender.AddFilter(filter);
            layout.ActivateOptions();
            newAppender.ActivateOptions();
            AsyncAppender appender2 = new AsyncAppender();

            appender2.AddAppender(newAppender);
            appender2.ActivateOptions();
            log4net.Repository.Hierarchy.Hierarchy hierarchy1 = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.CreateRepository(this.string_0);
            hierarchy1.Root.AddAppender(appender2);
            hierarchy1.Configured = true;
        }
Beispiel #2
0
        public void AddWpfListener(ScrollViewer scrollViewer, RichTextBox rtbLog)
        {
            PatternLayout  layout    = new PatternLayout("%message");
            WpfRtfAppender appender1 = new WpfRtfAppender(scrollViewer, rtbLog)
            {
                Layout = layout
            };

            this.wpfRtfAppender_0 = appender1;
            LevelRangeFilter filter = new LevelRangeFilter
            {
                LevelMin = this.level_0,
                LevelMax = this.level_1
            };

            this.wpfRtfAppender_0.AddFilter(filter);
            layout.ActivateOptions();
            this.wpfRtfAppender_0.ActivateOptions();
            AsyncAppender newAppender = new AsyncAppender();

            newAppender.AddAppender(this.wpfRtfAppender_0);
            newAppender.ActivateOptions();
            ((log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository(this.string_0)).Root.AddAppender(newAppender);
        }