コード例 #1
0
        protected override void Write(LogEventInfo logEvent)
        {
            WpfRichTextBoxRowColoringRule matchingRule = null;

            foreach (WpfRichTextBoxRowColoringRule rr in RowColoringRules)
            {
                if (rr.CheckCondition(logEvent))
                {
                    matchingRule = rr;
                    break;
                }
            }

            if (UseDefaultRowColoringRules && matchingRule == null)
            {
                foreach (WpfRichTextBoxRowColoringRule rr in DefaultRowColoringRules)
                {
                    if (rr.CheckCondition(logEvent))
                    {
                        matchingRule = rr;
                        break;
                    }
                }
            }

            if (matchingRule == null)
            {
                matchingRule = WpfRichTextBoxRowColoringRule.Default;
            }

            string logMessage = Layout.Render(logEvent);

            Application.Current.Dispatcher.Invoke(new Action(() => SendTheMessageToRichTextBox(logMessage, matchingRule)));
        }
コード例 #2
0
        private void SendTheMessageToRichTextBox(string logMessage, WpfRichTextBoxRowColoringRule rule)
        {
            var rtbx = TargetRichTextBox;

            logMessage = logMessage.Replace("\n", "\r");
            var tr = new TextRange(rtbx.Document.ContentEnd, rtbx.Document.ContentEnd)
            {
                Text = logMessage + "\r"
            };

            tr.ApplyPropertyValue(TextElement.ForegroundProperty,
                                  new SolidColorBrush(GetColorFromString(rule.FontColor, (Brush)tr.GetPropertyValue(TextElement.ForegroundProperty)))
                                  );
            tr.ApplyPropertyValue(TextElement.BackgroundProperty,
                                  new SolidColorBrush(GetColorFromString(rule.BackgroundColor, (Brush)tr.GetPropertyValue(TextElement.BackgroundProperty)))
                                  );
            tr.ApplyPropertyValue(TextElement.FontStyleProperty, rule.Style);
            tr.ApplyPropertyValue(TextElement.FontWeightProperty, rule.Weight);

            if (MaxLines > 0)
            {
                _lineCount++;
                if (_lineCount > MaxLines)
                {
                    tr = new TextRange(rtbx.Document.ContentStart, rtbx.Document.ContentEnd);
                    tr.Text.Remove(0, tr.Text.IndexOf('\n'));
                    _lineCount--;
                }
            }

            if (AutoScroll)
            {
                rtbx.ScrollToEnd();
            }
        }
コード例 #3
0
        private void SendTheMessageToRichTextBox(string logMessage, WpfRichTextBoxRowColoringRule rule)
        {
            System.Windows.Controls.RichTextBox rtbx = this.TargetRichTextBox;

            TextRange tr = new TextRange(rtbx.Document.ContentEnd, rtbx.Document.ContentEnd);

            tr.Text = logMessage + "\n";
            tr.ApplyPropertyValue(TextElement.ForegroundProperty,
                                  new SolidColorBrush(GetColorFromString(rule.FontColor, (Brush)tr.GetPropertyValue(TextElement.ForegroundProperty)))
                                  );
            tr.ApplyPropertyValue(TextElement.BackgroundProperty,
                                  new SolidColorBrush(GetColorFromString(rule.BackgroundColor, (Brush)tr.GetPropertyValue(TextElement.BackgroundProperty)))
                                  );
            tr.ApplyPropertyValue(TextElement.FontStyleProperty, rule.Style);
            tr.ApplyPropertyValue(TextElement.FontWeightProperty, rule.Weight);

            //int startIndex = rtbx.Text.Length;
            //rtbx.SelectionStart = startIndex;
            //rtbx.SelectionBackColor = GetColorFromString(rule.BackgroundColor, rtbx.BackColor);
            //rtbx.SelectionColor = GetColorFromString(rule.FontColor, rtbx.ForeColor);
            //rtbx.SelectionFont = new Font(rtbx.SelectionFont, rtbx.SelectionFont.Style ^ rule.Style);
            //rtbx.AppendText(logMessage + "\n");
            //rtbx.SelectionLength = rtbx.Text.Length - rtbx.SelectionStart;

            //// find word to color
            //foreach (RichTextBoxWordColoringRule wordRule in this.WordColoringRules)
            //{
            //    MatchCollection mc = wordRule.CompiledRegex.Matches(rtbx.Text, startIndex);
            //    foreach (Match m in mc)
            //    {
            //        rtbx.SelectionStart = m.Index;
            //        rtbx.SelectionLength = m.Length;
            //        rtbx.SelectionBackColor = GetColorFromString(wordRule.BackgroundColor, rtbx.BackColor);
            //        rtbx.SelectionColor = GetColorFromString(wordRule.FontColor, rtbx.ForeColor);
            //        rtbx.SelectionFont = new Font(rtbx.SelectionFont, rtbx.SelectionFont.Style ^ wordRule.Style);
            //    }
            //}

            if (this.MaxLines > 0)
            {
                this.lineCount++;
                if (this.lineCount > this.MaxLines)
                {
                    tr = new TextRange(rtbx.Document.ContentStart, rtbx.Document.ContentEnd);
                    tr.Text.Remove(0, tr.Text.IndexOf('\n'));
                    this.lineCount--;
                }
            }

            if (this.AutoScroll)
            {
                //rtbx.Select(rtbx.TextLength, 0);
                rtbx.ScrollToEnd();
            }
        }
コード例 #4
0
        private void SendTheMessageToRichTextBox(string logMessage, WpfRichTextBoxRowColoringRule rule)
        {
            foreach (RichTextBox richTextBox in m_targetRichTextBoxs)
            {
                var tr = new TextRange(richTextBox.Document.ContentEnd, richTextBox.Document.ContentEnd)
                {
                    Text = logMessage + "\n"
                };

                if (rule.FontColor != "Empty")
                {
                    tr.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush((Color)colorConverter.ConvertFromString(rule.FontColor)));
                }

                if (rule.BackgroundColor != "Empty")
                {
                    tr.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush((Color)colorConverter.ConvertFromString(rule.BackgroundColor)));
                }

                tr.ApplyPropertyValue(TextElement.FontStyleProperty, rule.Style);
                tr.ApplyPropertyValue(TextElement.FontWeightProperty, rule.Weight);

                if (MaxLines > 0)
                {
                    lineCount++;
                    if (lineCount > MaxLines)
                    {
                        tr = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
                        tr.Text.Remove(0, tr.Text.IndexOf('\n'));
                        lineCount--;
                    }
                }

                if (AutoScroll)
                {
                    richTextBox.ScrollToEnd();
                }
            }
        }
コード例 #5
0
        protected override void Write(LogEventInfo logEvent)
        {
            WpfRichTextBoxRowColoringRule matchingRule = null;

            foreach (WpfRichTextBoxRowColoringRule rr in this.RowColoringRules)
            {
                if (rr.CheckCondition(logEvent))
                {
                    matchingRule = rr;
                    break;
                }
            }

            if (this.UseDefaultRowColoringRules && matchingRule == null)
            {
                foreach (WpfRichTextBoxRowColoringRule rr in DefaultRowColoringRules)
                {
                    if (rr.CheckCondition(logEvent))
                    {
                        matchingRule = rr;
                        break;
                    }
                }
            }

            if (matchingRule == null)
            {
                matchingRule = WpfRichTextBoxRowColoringRule.Default;
            }

            string logMessage = this.Layout.Render(logEvent);

            //this.TargetRichTextBox.Invoke(new DelSendTheMessageToRichTextBox(this.SendTheMessageToRichTextBox), new object[] { logMessage, matchingRule });
            TargetRichTextBox.Dispatcher.BeginInvoke(new Action(() =>
            {
                SendTheMessageToRichTextBox(logMessage, matchingRule);
            }));
        }
コード例 #6
0
 static WpfRichTextBoxRowColoringRule()
 {
     Default = new WpfRichTextBoxRowColoringRule();
 }
コード例 #7
0
        private void SendTheMessageToRichTextBox(string logMessage, WpfRichTextBoxRowColoringRule rule)
        {
            System.Windows.Controls.RichTextBox rtbx = this.TargetRichTextBox;

            Paragraph paragraf = new Paragraph(new Run(logMessage));

            paragraf.Foreground = new SolidColorBrush(GetColorFromString(rule.FontColor, (SolidColorBrush)paragraf.Foreground));

            SolidColorBrush defaultBackgroundProperty = (SolidColorBrush)paragraf.Background;

            if (defaultBackgroundProperty == null)
            {
                defaultBackgroundProperty = Brushes.White;
            }
            paragraf.Background = new SolidColorBrush(GetColorFromString(rule.BackgroundColor, defaultBackgroundProperty));
            paragraf.FontStyle  = rule.Style;
            paragraf.FontWeight = rule.Weight;
            rtbx.Document.Blocks.Add(paragraf);

            //TextRange tr = new TextRange(rtbx.Document.ContentEnd, rtbx.Document.ContentEnd);
            //tr.Text = logMessage + "\n";
            //tr.ApplyPropertyValue(TextElement.ForegroundProperty,
            //    new SolidColorBrush(GetColorFromString(rule.FontColor, (SolidColorBrush)tr.GetPropertyValue(TextElement.ForegroundProperty)))
            //);

            //SolidColorBrush defaultBackgroundProperty = (SolidColorBrush)tr.GetPropertyValue(TextElement.BackgroundProperty);
            //if (defaultBackgroundProperty == null)
            //    defaultBackgroundProperty = Brushes.White;
            //tr.ApplyPropertyValue(TextElement.BackgroundProperty,
            //    new SolidColorBrush(GetColorFromString(rule.BackgroundColor, defaultBackgroundProperty))
            //);
            //tr.ApplyPropertyValue(TextElement.FontStyleProperty, rule.Style);
            //tr.ApplyPropertyValue(TextElement.FontWeightProperty, rule.Weight);

            //int startIndex = rtbx.Text.Length;
            //rtbx.SelectionStart = startIndex;
            //rtbx.SelectionBackColor = GetColorFromString(rule.BackgroundColor, rtbx.BackColor);
            //rtbx.SelectionColor = GetColorFromString(rule.FontColor, rtbx.ForeColor);
            //rtbx.SelectionFont = new Font(rtbx.SelectionFont, rtbx.SelectionFont.Style ^ rule.Style);
            //rtbx.AppendText(logMessage + "\n");
            //rtbx.SelectionLength = rtbx.Text.Length - rtbx.SelectionStart;

            //// find word to color
            //foreach (RichTextBoxWordColoringRule wordRule in this.WordColoringRules)
            //{
            //    MatchCollection mc = wordRule.CompiledRegex.Matches(rtbx.Text, startIndex);
            //    foreach (Match m in mc)
            //    {
            //        rtbx.SelectionStart = m.Index;
            //        rtbx.SelectionLength = m.Length;
            //        rtbx.SelectionBackColor = GetColorFromString(wordRule.BackgroundColor, rtbx.BackColor);
            //        rtbx.SelectionColor = GetColorFromString(wordRule.FontColor, rtbx.ForeColor);
            //        rtbx.SelectionFont = new Font(rtbx.SelectionFont, rtbx.SelectionFont.Style ^ wordRule.Style);
            //    }
            //}

            //if (this.MaxLines > 0)
            //{
            //    this.lineCount++;
            //    if (this.lineCount > this.MaxLines)
            //    {
            //        tr = new TextRange(rtbx.Document.ContentStart, rtbx.Document.ContentEnd);
            //        tr.Text.Remove(0, tr.Text.IndexOf('\n'));
            //        this.lineCount--;
            //    }
            //}

            if (this.AutoScroll)
            {
                //rtbx.Select(rtbx.TextLength, 0);
                rtbx.ScrollToEnd();
            }
        }
コード例 #8
0
        protected override void Write(LogEventInfo logEvent)
        {
            WpfRichTextBoxRowColoringRule matchingRule = null;

            foreach (WpfRichTextBoxRowColoringRule rr in this.RowColoringRules)
            {
                if (rr.CheckCondition(logEvent))
                {
                    matchingRule = rr;
                    break;
                }
            }

            if (this.UseDefaultRowColoringRules && matchingRule == null)
            {
                foreach (WpfRichTextBoxRowColoringRule rr in DefaultRowColoringRules)
                {
                    if (rr.CheckCondition(logEvent))
                    {
                        matchingRule = rr;
                        break;
                    }
                }
            }

            if (matchingRule == null)
            {
                matchingRule = WpfRichTextBoxRowColoringRule.Default;
            }

            string logMessage = this.Layout.Render(logEvent);

            //    //this.TargetRichTextBox.Invoke(new DelSendTheMessageToRichTextBox(this.SendTheMessageToRichTextBox), new object[] { logMessage, matchingRule });
            //    System.Windows.Application.Current.MainWindow.Dispatcher.Invoke(new Action(() =>
            //    {
            //        SendTheMessageToRichTextBox(logMessage, matchingRule);
            //    }));
            //}

            //private static Color GetColorFromString(string color, Brush defaultColor)
            //{
            //    if (color == "Empty")
            //    {
            //        return (Color)colorConverter.ConvertFrom(defaultColor);
            //    }

            //    return (Color)colorConverter.ConvertFromString(color);
            //}
            //this.TargetRichTextBox.Invoke(new DelSendTheMessageToRichTextBox(this.SendTheMessageToRichTextBox), new object[] { logMessage, matchingRule });
            if (System.Windows.Application.Current.Dispatcher.CheckAccess() == false)
            {
                System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    SendTheMessageToRichTextBox(logMessage, matchingRule);
                }));
            }
            else
            {
                SendTheMessageToRichTextBox(logMessage, matchingRule);
            }
        }
コード例 #9
0
ファイル: WpfRichTextBoxTarget.cs プロジェクト: unicloud/AFRP
        private void SendTheMessageToRichTextBox(string logMessage, WpfRichTextBoxRowColoringRule rule)
        {
            System.Windows.Controls.RichTextBox rtbx = this.TargetRichTextBox;

            TextRange tr = new TextRange(rtbx.Document.ContentEnd, rtbx.Document.ContentEnd);
            tr.Text = logMessage + "\n";
            tr.ApplyPropertyValue(TextElement.ForegroundProperty,
                new SolidColorBrush(GetColorFromString(rule.FontColor, (Brush)tr.GetPropertyValue(TextElement.ForegroundProperty)))
            );
            tr.ApplyPropertyValue(TextElement.BackgroundProperty,
                new SolidColorBrush(GetColorFromString(rule.BackgroundColor, (Brush)tr.GetPropertyValue(TextElement.BackgroundProperty)))
            );
            tr.ApplyPropertyValue(TextElement.FontStyleProperty, rule.Style);
            tr.ApplyPropertyValue(TextElement.FontWeightProperty, rule.Weight);

            //int startIndex = rtbx.Text.Length;
            //rtbx.SelectionStart = startIndex;
            //rtbx.SelectionBackColor = GetColorFromString(rule.BackgroundColor, rtbx.BackColor);
            //rtbx.SelectionColor = GetColorFromString(rule.FontColor, rtbx.ForeColor);
            //rtbx.SelectionFont = new Font(rtbx.SelectionFont, rtbx.SelectionFont.Style ^ rule.Style);
            //rtbx.AppendText(logMessage + "\n");
            //rtbx.SelectionLength = rtbx.Text.Length - rtbx.SelectionStart;

            //// find word to color
            //foreach (RichTextBoxWordColoringRule wordRule in this.WordColoringRules)
            //{
            //    MatchCollection mc = wordRule.CompiledRegex.Matches(rtbx.Text, startIndex);
            //    foreach (Match m in mc)
            //    {
            //        rtbx.SelectionStart = m.Index;
            //        rtbx.SelectionLength = m.Length;
            //        rtbx.SelectionBackColor = GetColorFromString(wordRule.BackgroundColor, rtbx.BackColor);
            //        rtbx.SelectionColor = GetColorFromString(wordRule.FontColor, rtbx.ForeColor);
            //        rtbx.SelectionFont = new Font(rtbx.SelectionFont, rtbx.SelectionFont.Style ^ wordRule.Style);
            //    }
            //}

            if (this.MaxLines > 0)
            {
                this.lineCount++;
                if (this.lineCount > this.MaxLines)
                {
                    tr = new TextRange(rtbx.Document.ContentStart, rtbx.Document.ContentEnd);
                    tr.Text.Remove(0, tr.Text.IndexOf('\n'));
                    this.lineCount--;
                }
            }

            if (this.AutoScroll)
            {
                //rtbx.Select(rtbx.TextLength, 0);
                rtbx.ScrollToEnd();
            }
        }
コード例 #10
0
 static WpfRichTextBoxRowColoringRule()
 {
     Default = new WpfRichTextBoxRowColoringRule();
 }
コード例 #11
0
        private void SendTheMessageToRichTextBox(string logMessage, WpfRichTextBoxRowColoringRule rule)
        {
            foreach (RichTextBox richTextBox in m_targetRichTextBoxs)
            {
                var tr = new TextRange(richTextBox.Document.ContentEnd, richTextBox.Document.ContentEnd) {Text = logMessage + "\n"};

                if (rule.FontColor != "Empty")
                    tr.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush((Color) colorConverter.ConvertFromString(rule.FontColor)));

                if (rule.BackgroundColor != "Empty")
                    tr.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush((Color) colorConverter.ConvertFromString(rule.BackgroundColor)));

                tr.ApplyPropertyValue(TextElement.FontStyleProperty, rule.Style);
                tr.ApplyPropertyValue(TextElement.FontWeightProperty, rule.Weight);

                if (MaxLines > 0)
                {
                    lineCount++;
                    if (lineCount > MaxLines)
                    {
                        tr = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
                        tr.Text.Remove(0, tr.Text.IndexOf('\n'));
                        lineCount--;
                    }
                }

                if (AutoScroll)
                {
                    richTextBox.ScrollToEnd();
                }
            }
        }
コード例 #12
0
ファイル: WpfRichTextBoxTarget.cs プロジェクト: GMZ/fo-dicom
        private void SendTheMessageToRichTextBox(string logMessage, WpfRichTextBoxRowColoringRule rule)
        {
            var rtbx = TargetRichTextBox;

            logMessage = logMessage.Replace("\n", "\r");
            var tr = new TextRange(rtbx.Document.ContentEnd, rtbx.Document.ContentEnd)
            {
                Text = logMessage + "\r"
            };
            tr.ApplyPropertyValue(TextElement.ForegroundProperty,
                new SolidColorBrush(GetColorFromString(rule.FontColor, (Brush)tr.GetPropertyValue(TextElement.ForegroundProperty)))
            );
            tr.ApplyPropertyValue(TextElement.BackgroundProperty,
                new SolidColorBrush(GetColorFromString(rule.BackgroundColor, (Brush)tr.GetPropertyValue(TextElement.BackgroundProperty)))
            );
            tr.ApplyPropertyValue(TextElement.FontStyleProperty, rule.Style);
            tr.ApplyPropertyValue(TextElement.FontWeightProperty, rule.Weight);

            if (MaxLines > 0)
            {
                _lineCount++;
                if (_lineCount > MaxLines)
                {
                    tr = new TextRange(rtbx.Document.ContentStart, rtbx.Document.ContentEnd);
                    tr.Text.Remove(0, tr.Text.IndexOf('\n'));
                    _lineCount--;
                }
            }

            if (AutoScroll)
            {
                rtbx.ScrollToEnd();
            }
        }