Example #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;

            object[] args = new object[] { now.Year, now.Month, now.Day, now.Hour, now.Minute, Process.GetCurrentProcess().Id, path, this.string_0 };
            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", args));
            FileAppender newAppender = new FileAppender {
                File         = this.FileName,
                Layout       = layout,
                LockingModel = new FileAppender.MinimalLock()
            };
            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)LogManager.CreateRepository(this.string_0);
            hierarchy1.Root.AddAppender(appender2);
            hierarchy1.Configured = true;
        }
Example #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)LogManager.GetRepository(this.string_0)).Root.AddAppender(newAppender);
        }