Added export logs button to save logs for future debugging
All checks were successful
Build / build (push) Successful in 35s

This commit is contained in:
Ankitkumar Satapara
2026-04-29 16:02:14 +05:30
parent a9a3c385eb
commit 1463d5b3a8
2 changed files with 46 additions and 0 deletions

View File

@@ -1,6 +1,9 @@
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Text;
using System.Windows.Media;
using Microsoft.Win32;
namespace Nodify.Calculator
{
@@ -41,11 +44,50 @@ namespace Nodify.Calculator
public INodifyCommand ClearLogsCommand { get; }
public INodifyCommand ClosePanelCommand { get; }
public INodifyCommand ExportLogsCommand { get; }
public LogPanelViewModel()
{
ClearLogsCommand = new DelegateCommand(() => LogEntries.Clear());
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)

View File

@@ -135,6 +135,10 @@
<Button Content="🗑 Clear" Command="{Binding LogPanel.ClearLogsCommand}"
Background="Transparent" Foreground="#FFAAAAAA" BorderThickness="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}"
Background="Transparent" Foreground="#FFAAAAAA" BorderThickness="0"
Padding="6,2" FontSize="11" Cursor="Hand" />