protected override void Write(LogEventInfo logEvent)
{
WpfRichTextBoxRowColoringRule matchingRule = RowColoringRules.FirstOrDefault(rr => rr.CheckCondition(logEvent));
if (UseDefaultRowColoringRules && matchingRule == null)
{
foreach (var rr in DefaultRowColoringRules.Where(rr => rr.CheckCondition(logEvent)))
{
matchingRule = rr;
break;
}
}
if (matchingRule == null)
{
matchingRule = WpfRichTextBoxRowColoringRule.Default;
}
var logMessage = Layout.Render(logEvent);
if (System.Windows.Application.Current == null) return;
try
{
if (System.Windows.Application.Current.Dispatcher.CheckAccess() == false)
{
System.Windows.Application.Current.Dispatcher.Invoke(() => SendTheMessageToRichTextBox(logMessage, matchingRule));
}
else
{
SendTheMessageToRichTextBox(logMessage, matchingRule);
}
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}