LogWindow: Improve loading time
Some checks failed
Test / Run tests (push) Has been cancelled

This commit is contained in:
2025-08-20 16:32:25 +02:00
parent 07f9a0f522
commit de561d9737
2 changed files with 32 additions and 25 deletions

View File

@@ -561,9 +561,7 @@ namespace Elwig.Helpers {
Log = "Application",
Source = ".NET Runtime",
};
return log.Entries.Cast<EventLogEntry>()
.Where(e => e.Message.StartsWith("Application: Elwig.exe"))
.ToList();
return [.. log.Entries.OfType<EventLogEntry>().Where(e => e.InstanceId == 1026).Where(e => e.Message.StartsWith("Application: Elwig.exe"))];
}
public static int GetEntityIdetifierForPk(params object?[] primaryKey) {

View File

@@ -1,7 +1,9 @@
using Elwig.Helpers;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace Elwig.Windows {
public partial class LogWindow : Window {
@@ -11,28 +13,35 @@ namespace Elwig.Windows {
WindowState = WindowState.Maximized;
}
private void Window_Loaded(object sender, RoutedEventArgs evt) {
var log = Utils.GetLogEntries();
EventList.ItemsSource = log
.Select(e => new {
Event = e,
Lines = e.Message.Split('\n').ToArray(),
})
.Select(e => new {
e.Event,
Exception = e.Lines.FirstOrDefault(l => l.StartsWith("Exception Info: "))?[16..].Trim().Split(':', 2),
Location = e.Lines.FirstOrDefault(l => l.StartsWith(" at Elwig."))?[5..].Trim(),
})
.Select(e => new {
e.Event,
e.Exception,
ExceptionName = e.Exception?[0].Trim(),
ExceptionMessage = e.Exception?.Length >= 2 ? e.Exception?[1].Trim() : null,
e.Location,
})
.OrderByDescending(e => e.Event.TimeGenerated)
.ToList();
EventList.SelectedIndex = 0;
private async void Window_Loaded(object sender, RoutedEventArgs evt) {
Mouse.OverrideCursor = Cursors.Wait;
await Task.Run(async () => {
var log = Utils.GetLogEntries();
var list = log
.Select(e => new {
Event = e,
Lines = e.Message.Split('\n').ToArray(),
})
.Select(e => new {
e.Event,
Exception = e.Lines.FirstOrDefault(l => l.StartsWith("Exception Info: "))?[16..].Trim().Split(':', 2),
Location = e.Lines.FirstOrDefault(l => l.StartsWith(" at Elwig."))?[5..].Trim(),
})
.Select(e => new {
e.Event,
e.Exception,
ExceptionName = e.Exception?[0].Trim(),
ExceptionMessage = e.Exception?.Length >= 2 ? e.Exception?[1].Trim() : null,
e.Location,
})
.OrderByDescending(e => e.Event.TimeGenerated)
.ToList();
await App.MainDispatcher.BeginInvoke(() => {
EventList.ItemsSource = list;
EventList.SelectedIndex = 0;
});
});
Mouse.OverrideCursor = null;
}
private void EventList_SelectionChanged(object sender, RoutedEventArgs evt) {