Initial commit: SpdUp Windows Gaming Booster v1.0.0
- .NET 8 WPF app with full MVVM architecture - One-click boost: CPU, RAM, GPU, network, services, timer resolution - Real-time system monitor (LibreHardwareMonitor) - Auto game detection (30+ games) - RAM optimizer with kernel-level cleanup - Network optimizer (TCP registry tweaks) - Service manager, process manager, shader cache cleaner - Desktop widget overlay - Debug log viewer - Custom dark gaming theme with trans pride colors - 84 unit tests (xUnit) - Inno Setup installer script - Landing page website
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
using System.IO;
|
||||
|
||||
namespace SpdUp.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Application-wide logging service with live event for UI consumption.
|
||||
/// </summary>
|
||||
public static class Logger
|
||||
{
|
||||
private static readonly object _lock = new();
|
||||
private static readonly string _logDir = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SpdUp", "Logs");
|
||||
|
||||
/// <summary>Fired on every log write – subscribers receive the formatted line.</summary>
|
||||
public static event Action<string>? LogWritten;
|
||||
|
||||
static Logger()
|
||||
{
|
||||
Directory.CreateDirectory(_logDir);
|
||||
}
|
||||
|
||||
private static string LogFile => Path.Combine(_logDir, $"SpdUp_{DateTime.Now:yyyy-MM-dd}.log");
|
||||
|
||||
public static void Info(string message) => Write("INFO", message);
|
||||
public static void Warn(string message) => Write("WARN", message);
|
||||
public static void Error(string message, Exception? ex = null)
|
||||
{
|
||||
var msg = ex is null ? message : $"{message} | {ex.GetType().Name}: {ex.Message}\n{ex.StackTrace}";
|
||||
Write("ERROR", msg);
|
||||
}
|
||||
|
||||
private static void Write(string level, string message)
|
||||
{
|
||||
var line = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}] [{level}] {message}";
|
||||
lock (_lock)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.AppendAllText(LogFile, line + Environment.NewLine);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Swallow – logging must never crash the app.
|
||||
}
|
||||
}
|
||||
|
||||
// Notify UI subscribers
|
||||
try { LogWritten?.Invoke(line); } catch { }
|
||||
|
||||
#if DEBUG
|
||||
System.Diagnostics.Debug.WriteLine(line);
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes log files older than the specified number of days.
|
||||
/// </summary>
|
||||
public static void PurgeOldLogs(int keepDays = 14)
|
||||
{
|
||||
try
|
||||
{
|
||||
var cutoff = DateTime.Now.AddDays(-keepDays);
|
||||
foreach (var file in Directory.GetFiles(_logDir, "SpdUp_*.log"))
|
||||
{
|
||||
if (File.GetCreationTime(file) < cutoff)
|
||||
File.Delete(file);
|
||||
}
|
||||
}
|
||||
catch { /* best-effort */ }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user