Files
Phil-icyou 19ba425e79 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
2026-03-08 17:34:45 +01:00

72 lines
2.1 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 */ }
}
}