瀏覽代碼

日志倒置

陈国伟 3 年之前
父節點
當前提交
10f5f0b44d
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      FastGithub.UI/UdpLogListBox.xaml.cs

+ 6 - 1
FastGithub.UI/UdpLogListBox.xaml.cs

@@ -9,6 +9,7 @@ namespace FastGithub.UI
     /// </summary>
     public partial class UdpLogListBox : UserControl
     {
+        private readonly int maxLogCount = 100;
         public ObservableCollection<UdpLog> LogList { get; } = new ObservableCollection<UdpLog>();
 
         public UdpLogListBox()
@@ -28,7 +29,11 @@ namespace FastGithub.UI
                     var log = await UdpLogger.GetUdpLogAsync();
                     if (log != null)
                     {
-                        this.LogList.Add(log);
+                        this.LogList.Insert(0, log);
+                        if (this.LogList.Count > this.maxLogCount)
+                        {
+                            this.LogList.RemoveAt(this.maxLogCount);
+                        }
                     }
                 }
                 catch (Exception)