641267081a
Neue Einstellung "Protokoll auto-leeren - Eintraege aelter als (Tage)". 0 = aus (alle Eintraege bleiben), >0 entfernt aeltere Eintraege. - UserSettings.LogRetentionDays (Standard 0). - Logger.PruneOlderThan(days): parst den Zeitstempel-Prefix je Zeile und entfernt zu alte; Zeilen ohne Zeitstempel bleiben erhalten. - Ausgefuehrt beim Start, vor jedem Sync (Coordinator), beim Oeffnen des Protokolls und beim Speichern der Einstellungen. - SettingsForm: NumericUpDown (0-3650). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
93 lines
2.9 KiB
C#
93 lines
2.9 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
using StarfaceOutlookSync.Models;
|
|
using StarfaceOutlookSync.Services;
|
|
|
|
namespace StarfaceOutlookSync.UI
|
|
{
|
|
/// <summary>Zeigt das Sync-Protokoll an (read-only) mit Aktualisieren/Leeren.</summary>
|
|
public class LogViewerForm : Form
|
|
{
|
|
private TextBox _txt;
|
|
private Button _btnClose;
|
|
private Panel _panel;
|
|
|
|
public LogViewerForm()
|
|
{
|
|
Text = "Protokoll";
|
|
Size = new Size(720, 500);
|
|
StartPosition = FormStartPosition.CenterParent;
|
|
Font = new Font("Segoe UI", 9);
|
|
|
|
_txt = new TextBox
|
|
{
|
|
Multiline = true,
|
|
ReadOnly = true,
|
|
ScrollBars = ScrollBars.Both,
|
|
WordWrap = false,
|
|
Dock = DockStyle.Fill,
|
|
BackColor = Color.White,
|
|
Font = new Font("Consolas", 9)
|
|
};
|
|
|
|
_panel = new Panel { Dock = DockStyle.Bottom, Height = 44 };
|
|
|
|
var btnRefresh = new Button { Text = "Aktualisieren", Left = 10, Top = 8, Width = 100, Height = 28 };
|
|
btnRefresh.Click += (s, e) => LoadLog();
|
|
|
|
var btnClear = new Button { Text = "Leeren", Left = 118, Top = 8, Width = 80, Height = 28 };
|
|
btnClear.Click += (s, e) =>
|
|
{
|
|
if (MessageBox.Show("Protokoll wirklich leeren?", "Protokoll",
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
{
|
|
Logger.Clear();
|
|
LoadLog();
|
|
}
|
|
};
|
|
|
|
var btnFolder = new Button { Text = "Ordner oeffnen", Left = 206, Top = 8, Width = 120, Height = 28 };
|
|
btnFolder.Click += (s, e) => OpenFolder();
|
|
|
|
_btnClose = new Button
|
|
{
|
|
Text = "Schliessen", Top = 8, Width = 100, Height = 28,
|
|
Anchor = AnchorStyles.Top | AnchorStyles.Right
|
|
};
|
|
_btnClose.Click += (s, e) => Close();
|
|
|
|
_panel.Controls.AddRange(new Control[] { btnRefresh, btnClear, btnFolder, _btnClose });
|
|
|
|
Controls.Add(_txt);
|
|
Controls.Add(_panel);
|
|
|
|
Load += (s, e) =>
|
|
{
|
|
_btnClose.Left = _panel.ClientSize.Width - _btnClose.Width - 10;
|
|
LoadLog();
|
|
};
|
|
}
|
|
|
|
private void LoadLog()
|
|
{
|
|
Logger.PruneOlderThan(UserSettings.Load().LogRetentionDays);
|
|
_txt.Text = Logger.ReadAll();
|
|
_txt.SelectionStart = _txt.TextLength;
|
|
_txt.ScrollToCaret();
|
|
}
|
|
|
|
private void OpenFolder()
|
|
{
|
|
try
|
|
{
|
|
var dir = Path.GetDirectoryName(Logger.LogFilePath);
|
|
Process.Start(new ProcessStartInfo { FileName = dir, UseShellExecute = true });
|
|
}
|
|
catch { }
|
|
}
|
|
}
|
|
}
|