Added export logs button to save logs for future debugging
All checks were successful
Build / build (push) Successful in 35s
All checks were successful
Build / build (push) Successful in 35s
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
|
||||||
namespace Nodify.Calculator
|
namespace Nodify.Calculator
|
||||||
{
|
{
|
||||||
@@ -41,11 +44,50 @@ namespace Nodify.Calculator
|
|||||||
|
|
||||||
public INodifyCommand ClearLogsCommand { get; }
|
public INodifyCommand ClearLogsCommand { get; }
|
||||||
public INodifyCommand ClosePanelCommand { get; }
|
public INodifyCommand ClosePanelCommand { get; }
|
||||||
|
public INodifyCommand ExportLogsCommand { get; }
|
||||||
|
|
||||||
public LogPanelViewModel()
|
public LogPanelViewModel()
|
||||||
{
|
{
|
||||||
ClearLogsCommand = new DelegateCommand(() => LogEntries.Clear());
|
ClearLogsCommand = new DelegateCommand(() => LogEntries.Clear());
|
||||||
ClosePanelCommand = new DelegateCommand(() => IsOpen = false);
|
ClosePanelCommand = new DelegateCommand(() => IsOpen = false);
|
||||||
|
ExportLogsCommand = new DelegateCommand(ExportLogs);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ExportLogs()
|
||||||
|
{
|
||||||
|
if (LogEntries.Count == 0)
|
||||||
|
{
|
||||||
|
System.Windows.MessageBox.Show("There are no logs to export.", "Export Logs",
|
||||||
|
System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var dialog = new SaveFileDialog
|
||||||
|
{
|
||||||
|
Title = "Export Logs",
|
||||||
|
Filter = "Log file (*.log)|*.log|Text file (*.txt)|*.txt|All files (*.*)|*.*",
|
||||||
|
FileName = $"APIVisualExecutor_Logs_{DateTime.Now:yyyyMMdd_HHmmss}.log"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (dialog.ShowDialog() != true)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
foreach (var entry in LogEntries)
|
||||||
|
{
|
||||||
|
sb.Append('[').Append(entry.Timestamp).Append("] [")
|
||||||
|
.Append(entry.Level).Append("] ")
|
||||||
|
.AppendLine(entry.Message);
|
||||||
|
}
|
||||||
|
File.WriteAllText(dialog.FileName, sb.ToString(), Encoding.UTF8);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.Windows.MessageBox.Show($"Failed to export logs: {ex.Message}", "Export Logs",
|
||||||
|
System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteLog(string message, logType logtype = logType.Information)
|
public void WriteLog(string message, logType logtype = logType.Information)
|
||||||
|
|||||||
@@ -135,6 +135,10 @@
|
|||||||
<Button Content="🗑 Clear" Command="{Binding LogPanel.ClearLogsCommand}"
|
<Button Content="🗑 Clear" Command="{Binding LogPanel.ClearLogsCommand}"
|
||||||
Background="Transparent" Foreground="#FFAAAAAA" BorderThickness="0"
|
Background="Transparent" Foreground="#FFAAAAAA" BorderThickness="0"
|
||||||
Padding="6,2" FontSize="11" Cursor="Hand" Margin="0,0,4,0" />
|
Padding="6,2" FontSize="11" Cursor="Hand" Margin="0,0,4,0" />
|
||||||
|
<Button Content="💾 Export" Command="{Binding LogPanel.ExportLogsCommand}"
|
||||||
|
ToolTip="Export all logs to a file"
|
||||||
|
Background="Transparent" Foreground="#FFAAAAAA" BorderThickness="0"
|
||||||
|
Padding="6,2" FontSize="11" Cursor="Hand" Margin="0,0,4,0" />
|
||||||
<Button Content="✕" Command="{Binding LogPanel.ClosePanelCommand}"
|
<Button Content="✕" Command="{Binding LogPanel.ClosePanelCommand}"
|
||||||
Background="Transparent" Foreground="#FFAAAAAA" BorderThickness="0"
|
Background="Transparent" Foreground="#FFAAAAAA" BorderThickness="0"
|
||||||
Padding="6,2" FontSize="11" Cursor="Hand" />
|
Padding="6,2" FontSize="11" Cursor="Hand" />
|
||||||
|
|||||||
Reference in New Issue
Block a user