From 9a51bf04de96bdb0003999933b4b090c920dcba4 Mon Sep 17 00:00:00 2001 From: Genteure Date: Sun, 1 Aug 2021 18:02:46 +0800 Subject: [PATCH] WPF: Adjust log panel, fix #222 --- BililiveRecorder.WPF/Controls/LogPanel.xaml | 46 ++++++---- .../Controls/LogPanel.xaml.cs | 19 ++++ .../Properties/Strings.Designer.cs | 90 +++++++++++++++++++ BililiveRecorder.WPF/Properties/Strings.resx | 30 +++++++ BililiveRecorder.WPF/WpfLogEventSink.cs | 15 +--- 5 files changed, 172 insertions(+), 28 deletions(-) diff --git a/BililiveRecorder.WPF/Controls/LogPanel.xaml b/BililiveRecorder.WPF/Controls/LogPanel.xaml index 20cd4ba..674cea0 100644 --- a/BililiveRecorder.WPF/Controls/LogPanel.xaml +++ b/BililiveRecorder.WPF/Controls/LogPanel.xaml @@ -1,14 +1,19 @@ - - + @@ -22,13 +27,22 @@ - - - - + + - + + + + + + + + + diff --git a/BililiveRecorder.WPF/Controls/LogPanel.xaml.cs b/BililiveRecorder.WPF/Controls/LogPanel.xaml.cs index f16580d..976883e 100644 --- a/BililiveRecorder.WPF/Controls/LogPanel.xaml.cs +++ b/BililiveRecorder.WPF/Controls/LogPanel.xaml.cs @@ -1,5 +1,8 @@ +using System; +using System.Collections.Specialized; using System.Windows; using System.Windows.Controls; +using System.Windows.Media; #nullable enable namespace BililiveRecorder.WPF.Controls @@ -12,6 +15,22 @@ namespace BililiveRecorder.WPF.Controls public LogPanel() { this.InitializeComponent(); + ((INotifyCollectionChanged)this.logView.Items).CollectionChanged += this.LogView_CollectionChanged; + } + + private void LogView_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + try + { + if (!this.logView.IsMouseOver && VisualTreeHelper.GetChildrenCount(this.logView) > 0) + { + var border = (Border)VisualTreeHelper.GetChild(this.logView, 0); + var scrollViewer = (ScrollViewer)VisualTreeHelper.GetChild(border, 0); + scrollViewer.ScrollToBottom(); + } + } + catch (Exception) + { } } private void ListView_SizeChanged(object sender, SizeChangedEventArgs e) diff --git a/BililiveRecorder.WPF/Properties/Strings.Designer.cs b/BililiveRecorder.WPF/Properties/Strings.Designer.cs index 518b229..3670e98 100644 --- a/BililiveRecorder.WPF/Properties/Strings.Designer.cs +++ b/BililiveRecorder.WPF/Properties/Strings.Designer.cs @@ -340,6 +340,96 @@ namespace BililiveRecorder.WPF.Properties { } } + /// + /// Looks up a localized string similar to 级别. + /// + public static string LogPanel_Header_Level { + get { + return ResourceManager.GetString("LogPanel_Header_Level", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 消息. + /// + public static string LogPanel_Header_Message { + get { + return ResourceManager.GetString("LogPanel_Header_Message", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 房间号. + /// + public static string LogPanel_Header_RoomId { + get { + return ResourceManager.GetString("LogPanel_Header_RoomId", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 时间. + /// + public static string LogPanel_Header_Timestamp { + get { + return ResourceManager.GetString("LogPanel_Header_Timestamp", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 调试. + /// + public static string LogPanel_Level_Debug { + get { + return ResourceManager.GetString("LogPanel_Level_Debug", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 错误. + /// + public static string LogPanel_Level_Error { + get { + return ResourceManager.GetString("LogPanel_Level_Error", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 致命. + /// + public static string LogPanel_Level_Fatal { + get { + return ResourceManager.GetString("LogPanel_Level_Fatal", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 信息. + /// + public static string LogPanel_Level_Information { + get { + return ResourceManager.GetString("LogPanel_Level_Information", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 详细. + /// + public static string LogPanel_Level_Verbose { + get { + return ResourceManager.GetString("LogPanel_Level_Verbose", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 警告. + /// + public static string LogPanel_Level_Warning { + get { + return ResourceManager.GetString("LogPanel_Level_Warning", resourceCulture); + } + } + /// /// Looks up a localized string similar to 回放剪辑(正在处理中的数量). /// diff --git a/BililiveRecorder.WPF/Properties/Strings.resx b/BililiveRecorder.WPF/Properties/Strings.resx index a399e50..8966309 100644 --- a/BililiveRecorder.WPF/Properties/Strings.resx +++ b/BililiveRecorder.WPF/Properties/Strings.resx @@ -196,6 +196,36 @@ 右键点击可以复制单行日志 + + 级别 + + + 消息 + + + 房间号 + + + 时间 + + + 调试 + + + 错误 + + + 致命 + + + 信息 + + + 详细 + + + 警告 + 回放剪辑(正在处理中的数量) This feature is off by default, and will be removed in the future. diff --git a/BililiveRecorder.WPF/WpfLogEventSink.cs b/BililiveRecorder.WPF/WpfLogEventSink.cs index 915e554..755a836 100644 --- a/BililiveRecorder.WPF/WpfLogEventSink.cs +++ b/BililiveRecorder.WPF/WpfLogEventSink.cs @@ -11,7 +11,7 @@ namespace BililiveRecorder.WPF { internal class WpfLogEventSink : ILogEventSink { - private const int MAX_LINE = 60; + private const int MAX_LINE = 150; internal static object _lock = new object(); internal static ObservableCollection Logs = new ObservableCollection(); @@ -26,16 +26,7 @@ namespace BililiveRecorder.WPF var m = new LogModel { Timestamp = logEvent.Timestamp, - Level = logEvent.Level switch - { - LogEventLevel.Verbose => "Verbose", - LogEventLevel.Debug => "Debug", - LogEventLevel.Information => "Info", - LogEventLevel.Warning => "Warn", - LogEventLevel.Error => "Error", - LogEventLevel.Fatal => "Fatal", - _ => string.Empty, - }, + Level = logEvent.Level, Message = msg, }; @@ -69,7 +60,7 @@ namespace BililiveRecorder.WPF { public DateTimeOffset Timestamp { get; set; } - public string Level { get; set; } = string.Empty; + public LogEventLevel Level { get; set; } public string RoomId { get; set; } = string.Empty;