Rename project from DellMonitorControl to MonitorControl to reflect broader monitor compatibility beyond Dell hardware. Update all references in solution file, workflow, and project paths. Add DDC/CI rate limiting and throttling logic to prevent command failures: - Minimum 50ms interval between commands to same monitor - 8-second grace period after system resume before sending commands - 3-second cooldown after timeout to allow monitor recovery - Global semaphore to prevent command collisions Replace old icon with new generic monitor icon (ico and png formats).
78 lines
2.0 KiB
C#
78 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
namespace MonitorControl;
|
|
|
|
public static class DebugLogger
|
|
{
|
|
private static readonly List<string> _logs = new();
|
|
private static readonly object _lock = new();
|
|
private static readonly string _logFilePath;
|
|
|
|
static DebugLogger()
|
|
{
|
|
var tempPath = Path.Combine(Path.GetTempPath(), "CMM");
|
|
Directory.CreateDirectory(tempPath);
|
|
_logFilePath = Path.Combine(tempPath, "debug.log");
|
|
}
|
|
|
|
public static void Log(string message)
|
|
{
|
|
var entry = $"[{DateTime.Now:HH:mm:ss.fff}] {message}";
|
|
lock (_lock)
|
|
{
|
|
_logs.Add(entry);
|
|
try
|
|
{
|
|
File.AppendAllText(_logFilePath, entry + Environment.NewLine);
|
|
}
|
|
catch { }
|
|
}
|
|
}
|
|
|
|
public static void LogError(string message, Exception? ex = null)
|
|
{
|
|
var entry = ex != null
|
|
? $"[{DateTime.Now:HH:mm:ss.fff}] ERROR: {message} - {ex.GetType().Name}: {ex.Message}"
|
|
: $"[{DateTime.Now:HH:mm:ss.fff}] ERROR: {message}";
|
|
lock (_lock)
|
|
{
|
|
_logs.Add(entry);
|
|
if (ex != null)
|
|
_logs.Add($" Stack: {ex.StackTrace}");
|
|
try
|
|
{
|
|
File.AppendAllText(_logFilePath, entry + Environment.NewLine);
|
|
if (ex != null)
|
|
File.AppendAllText(_logFilePath, $" Stack: {ex.StackTrace}" + Environment.NewLine);
|
|
}
|
|
catch { }
|
|
}
|
|
}
|
|
|
|
public static string GetLogs()
|
|
{
|
|
lock (_lock)
|
|
{
|
|
return string.Join(Environment.NewLine, _logs);
|
|
}
|
|
}
|
|
|
|
public static void Clear()
|
|
{
|
|
lock (_lock)
|
|
{
|
|
_logs.Clear();
|
|
try
|
|
{
|
|
File.WriteAllText(_logFilePath, "");
|
|
}
|
|
catch { }
|
|
}
|
|
}
|
|
|
|
public static string LogFilePath => _logFilePath;
|
|
}
|