fix: improve diagnostics logging and log copy

This commit is contained in:
Meik
2026-03-10 10:02:53 +01:00
parent 24b33cd85a
commit ba3983ad8a
2 changed files with 36 additions and 2 deletions

View File

@@ -479,6 +479,8 @@
</Grid.RowDefinitions>
<TextBlock x:Name="StatusTextBlock" Grid.Row="0" Margin="0,0,0,6" Foreground="Gray"/>
<ListBox x:Name="LogListBox" Grid.Row="1"
SelectionMode="Extended"
KeyDown="LogListBox_KeyDown"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.CanContentScroll="True"/>

View File

@@ -7,6 +7,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.IO;
using C4IT.LIAM;
using C4IT.Logging;
@@ -33,6 +34,7 @@ namespace LiamWorkflowDiagnostics
private readonly ObservableCollection<string> _logEntries = new ObservableCollection<string>();
private ProviderTestSession _session;
private bool _isInitializingUi;
private dynamic _diagnosticsLogger;
private readonly string _settingsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "LiamWorkflowDiagnostics.settings.json");
public MainWindow()
@@ -65,7 +67,7 @@ namespace LiamWorkflowDiagnostics
var logDirectory = Path.Combine(baseDir, "logs");
Directory.CreateDirectory(logDirectory);
var logPath = Path.Combine(logDirectory, "LiamWorkflowDiagnostics.log");
cLogManagerFile.CreateInstance(logPath);
_diagnosticsLogger = cLogManagerFile.CreateInstance(logPath);
cLogManager.Instance.Level = LogLevels.Debug;
AppendLog($"Logdatei: {logPath} (Level: Debug)");
}
@@ -137,7 +139,8 @@ namespace LiamWorkflowDiagnostics
try
{
cLogManager.DefaultLogger?.LogEntry(level, message);
if (_diagnosticsLogger != null)
_diagnosticsLogger.LogEntry(level, message);
}
catch { /* ignore */ }
}
@@ -227,6 +230,35 @@ namespace LiamWorkflowDiagnostics
AppendLog("Log gelöscht.", LogLevels.Debug);
}
private void LogListBox_KeyDown(object sender, KeyEventArgs e)
{
if ((Keyboard.Modifiers & ModifierKeys.Control) != ModifierKeys.Control)
return;
if (e.Key == Key.A)
{
LogListBox.SelectAll();
e.Handled = true;
return;
}
if (e.Key != Key.C)
return;
var selectedLines = LogListBox.SelectedItems
.Cast<object>()
.Select(i => i?.ToString() ?? string.Empty)
.Where(i => !string.IsNullOrWhiteSpace(i))
.ToList();
if (selectedLines.Count == 0)
return;
Clipboard.SetText(string.Join(Environment.NewLine, selectedLines));
AppendLog($"Logzeilen in Zwischenablage kopiert: {selectedLines.Count}", LogLevels.Debug);
e.Handled = true;
}
private void LoadSettings()
{
ToolSettings settings = null;