コード例 #1
0
        private RichTextBoxParagraph CreateLogEntryParagraph(LogEntry logEntry)
        {
            var vm = ViewModel as LogViewerViewModel;

            if (vm == null)
            {
                return(null);
            }

            var paragraph = new RichTextBoxParagraph(logEntry);

            paragraph.MouseLeftButtonDown += OnParagraphMouseLeftButton;

            if (EnableIcons)
            {
                var icon = new Label()
                {
                    DataContext = logEntry
                };
                paragraph.Inlines.Add(icon);
            }

            if (EnableTextColoring)
            {
                paragraph.Foreground = ColorSets[logEntry.LogEvent];
            }

            paragraph.SetData(EnableTimestamp, EnableThreadId);

            return(paragraph);
        }
コード例 #2
0
        private RichTextBoxParagraph CreateLogEntryParagraph(LogEntry logEntry)
        {
            var paragraph = new RichTextBoxParagraph(logEntry);

            paragraph.MouseLeftButtonDown += OnParagraphMouseLeftButton;

            if (EnableIcons)
            {
                var icon = new Label
                {
                    DataContext = logEntry
                };

                paragraph.Inlines.Add(icon);
            }

            if (EnableTextColoring)
            {
                paragraph.Foreground = ColorSets[logEntry.LogEvent];
            }

            paragraph.SetData(EnableTimestamp, EnableThreadId, ShowMultilineMessagesExpanded);

            return(paragraph);
        }
コード例 #3
0
        public static void SetData(this RichTextBoxParagraph paragraph, bool showTimestamp = true, bool showThreadId = true)
        {
            var timestamp = $"{paragraph.LogEntry.Time} ";
            var toolTip   = new StringBuilder();

            if (!showTimestamp)
            {
                toolTip.AppendLine("Time: " + timestamp);
                timestamp = string.Empty;
            }

            toolTip.Append("Log event: " + paragraph.LogEntry.Log.Tag);
            paragraph.SetCurrentValue(System.Windows.FrameworkContentElement.ToolTipProperty, toolTip);

            var threadId = string.Empty;
            var data     = paragraph.LogEntry.Data;

            if (showThreadId && data.ContainsKey("ThreadId"))
            {
                threadId = $"[{data["ThreadId"]}] ";
            }

            var text = $"{timestamp}{threadId}{paragraph.LogEntry.Message}";

            paragraph.Inlines.Add(text);
        }
コード例 #4
0
        public static void SetData(this RichTextBoxParagraph paragraph, bool showTimestamp = true, bool showThreadId = true)
        {
            var timestamp = string.Format("{0} ", paragraph.LogEntry.Time);
            var toolTip   = new StringBuilder();

            if (!showTimestamp)
            {
                toolTip.AppendLine("Time: " + timestamp);
                timestamp = string.Empty;
            }

            toolTip.Append("Log event: " + paragraph.LogEntry.Log.Tag);
            paragraph.ToolTip = toolTip;

            var threadId = string.Empty;
            var data     = paragraph.LogEntry.Data;

            if (showThreadId && data.ContainsKey("ThreadId"))
            {
                threadId = string.Format("[{0}] ", data["ThreadId"]);
            }

            var text = string.Format("{0}{1}{2}", timestamp, threadId, paragraph.LogEntry.Message);

            paragraph.Inlines.Add(text);
        }
コード例 #5
0
        private RichTextBoxParagraph CreateLogEntryParagraph(LogEntry logEntry)
        {
            var vm = ViewModel as LogViewerViewModel;
            if (vm == null)
            {
                return null;
            }

            var paragraph = new RichTextBoxParagraph(logEntry);
            paragraph.MouseLeftButtonDown += OnParagraphMouseLeftButton;

            if (EnableIcons)
            {
                var icon = new Label() { DataContext = logEntry };
                paragraph.Inlines.Add(icon);
            }

            if (EnableTextColoring)
            {
                paragraph.Foreground = ColorSets[logEntry.LogEvent];
            }

            paragraph.SetData(EnableTimestamp, EnableThreadId);

            return paragraph;
        }
コード例 #6
0
        public static void SetData(this RichTextBoxParagraph paragraph, bool showTimestamp = true, bool showThreadId = true, bool showMultilineMessagesExpanded = false)
        {
            var timestamp = $"{paragraph.LogEntry.Time} ";
            var toolTip   = new StringBuilder();

            if (!showTimestamp)
            {
                toolTip.AppendLine("Time: " + timestamp);
                timestamp = string.Empty;
            }

            var logEntry = paragraph.LogEntry;

            toolTip.AppendLine($"Log type: {logEntry?.Log?.TargetType?.FullName}");

            // Note: last call must be Append instead of AppendLine
            toolTip.Append($"Log event: {logEntry?.LogEvent}");

            paragraph.SetCurrentValue(FrameworkContentElement.ToolTipProperty, toolTip.ToString());

            var threadId = string.Empty;

            if (showThreadId)
            {
                var data = logEntry?.Data;
                if (data != null && data.TryGetValue("ThreadId", out var existingThreadId))
                {
                    threadId = $"[{existingThreadId}] ";
                }
            }

            var message        = logEntry?.Message;
            var buttonRequired = false;

            if (!showMultilineMessagesExpanded && !string.IsNullOrEmpty(message))
            {
                var lines = message.Split('\n');
                if (lines.Length > 1)
                {
                    message        = lines[0].Trim();
                    buttonRequired = true;
                }
            }

            var text = $"{timestamp}{threadId}{message}";

            paragraph.Inlines.Clear();
            paragraph.Inlines.Add(text);

            if (!buttonRequired)
            {
                return;
            }

            var button = new TextBlock
            {
                Text   = "[...]",
                Margin = new Thickness(5, 0, 0, 0),
                Cursor = Cursors.SizeNWSE
            };

            button.MouseLeftButtonDown += (sender, args) => paragraph.SetData(showTimestamp, showThreadId, true);

            paragraph.Inlines.Add(button);
        }