Пример #1
0
        private void UpdateControl(LoggingEvent a_logging_event)
        {
            LevelTextStyle selectedStyle = m_level_mapping.Lookup(a_logging_event.Level) as LevelTextStyle;

            if (selectedStyle != null)
            {
                m_rich_text_box.SelectionBackColor = selectedStyle.BackColor;
                m_rich_text_box.SelectionColor     = selectedStyle.TextColor;
                m_rich_text_box.SelectionFont      = new Font(m_rich_text_box.Font, selectedStyle.FontStyle);
            }

            m_rich_text_box.AppendText(RenderLoggingEvent(a_logging_event));

            // Clear if too big.
            if (MaxLines > 0)
            {
                if (m_rich_text_box.Lines.Length > MaxLines)
                {
                    int pos = m_rich_text_box.GetFirstCharIndexFromLine(1);
                    m_rich_text_box.Select(0, pos);
                    m_rich_text_box.SelectedText = String.Empty;
                }
            }

            // Autoscroll.
            m_rich_text_box.Select(m_rich_text_box.TextLength, 0);
            m_rich_text_box.ScrollToCaret();
        }
        private void SetupLog4NET()
        {
            RichTextBoxAppender rba = new RichTextBoxAppender(logRichTextBox);

            rba.Threshold = Level.All;
            rba.Layout    = new PatternLayout(
                "%date{yyyy-MM-dd HH:mm:ss,fff} %-7level %-14logger %thread %class.%method - %message %newline");

            LevelTextStyle ilts = new LevelTextStyle();

            ilts.Level     = Level.Info;
            ilts.TextColor = Color.Black;
            rba.AddMapping(ilts);

            LevelTextStyle dlts = new LevelTextStyle();

            dlts.Level     = Level.Debug;
            dlts.TextColor = Color.LightBlue;
            rba.AddMapping(dlts);

            LevelTextStyle wlts = new LevelTextStyle();

            wlts.Level     = Level.Warn;
            wlts.TextColor = Color.Yellow;
            rba.AddMapping(wlts);

            LevelTextStyle elts = new LevelTextStyle();

            elts.Level     = Level.Error;
            elts.TextColor = Color.Red;
            rba.AddMapping(elts);

            BasicConfigurator.Configure(rba);
            rba.ActivateOptions();
        }
Пример #3
0
 public void AddMapping(LevelTextStyle a_mapping)
 {
     m_level_mapping.Add(a_mapping);
 }
 public void AddMapping(LevelTextStyle a_mapping)
 {
     m_level_mapping.Add(a_mapping);
 }