Beispiel #1
0
        private void Log_MessageBroadcasted(object sender, MessageBroadcastedEventArgs e)
        {
            if (e.Severity == Severity.Trace)
            {
                return;
            }

            // Invoke on UI thread
            InvokeOnUIThread(() =>
            {
                SolidColorBrush color;
                string severityIndicator;

                switch (e.Severity)
                {
                case Severity.Trace:
                    color             = Brushes.Gray;
                    severityIndicator = "T";
                    break;

                case Severity.Warning:
                    color             = Brushes.Orange;
                    severityIndicator = "!";
                    break;

                case Severity.Error:
                    color             = Brushes.Red;
                    severityIndicator = "E";
                    break;

                case Severity.Fatal:
                    color             = Brushes.Magenta;
                    severityIndicator = "F";
                    break;

                default:
                    color             = Brushes.Black;
                    severityIndicator = "I";
                    break;
                }

                var textRange = new TextRange(LogTextBox.Document.ContentEnd, LogTextBox.Document.ContentEnd)
                {
                    Text = $"[{e.Channel.Name}] {severityIndicator}: {e.Message}\n"
                };

                textRange.ApplyPropertyValue(TextElement.ForegroundProperty, color);
            });
        }
Beispiel #2
0
    /// <summary>
    /// Logs the message broadcasted.
    /// Tracks the severity of the log message and assigns it an appropriate
    /// Indicator and Color.
    /// Appends the log message to the TextView.
    /// It should be coloring it, but it isn't right now.
    /// </summary>
    /// <param name="sender">Sender.</param>
    /// <param name="e">E.</param>
    private void Log_MessageBroadcasted(object sender, MessageBroadcastedEventArgs e)
    {
        if (e.Severity == Severity.Trace)
        {
            return;
        }

        string       severityIndicator;
        ConsoleColor color;
        TextTag      logcolor = new TextTag("color");

        switch (e.Severity)
        {
        case Severity.Trace:
            color = ConsoleColor.Blue;
            logcolor.Foreground = "blue";
            severityIndicator   = "T";
            break;

        case Severity.Warning:
            color = ConsoleColor.Yellow;
            logcolor.Foreground = "yellow";
            severityIndicator   = "!";
            break;

        case Severity.Error:
            color = ConsoleColor.Red;
            logcolor.Foreground = "red";
            severityIndicator   = "E";
            break;

        case Severity.Fatal:
            color             = ConsoleColor.Magenta;
            severityIndicator = "F";
            break;

        default:
            color = ConsoleColor.White;
            logcolor.Foreground = "green";
            severityIndicator   = "I";
            break;
        }
        TextIter logend = LogView.Buffer.EndIter;

        LogView.Buffer.Insert(ref logend, $"[{e.Channel.Name}]:{severityIndicator}: {e.Message}\n");
        //  LogView.Buffer.ApplyTag(logcolor, logend, LogView.Buffer.EndIter);
        Console.ForegroundColor = color;
        Console.WriteLine($"[{e.Channel.Name}]:{severityIndicator}: {e.Message}\n");
    }