-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDebugLogger.cs
More file actions
81 lines (71 loc) · 2.23 KB
/
Copy pathDebugLogger.cs
File metadata and controls
81 lines (71 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.IO;
namespace DigimonNOAccess
{
/// <summary>
/// Simple file logger for debugging.
/// Logs to Mods folder for easy access.
/// </summary>
public static class DebugLogger
{
private static string _logPath;
private static object _lock = new object();
private static bool _initialized = false;
public static void Initialize()
{
if (_initialized)
return;
try
{
// Log to the Mods folder where our DLL is
string modsFolder = Path.GetDirectoryName(typeof(DebugLogger).Assembly.Location);
_logPath = Path.Combine(modsFolder, "DigimonNOAccess_debug.log");
// Clear old log on startup
if (File.Exists(_logPath))
{
File.Delete(_logPath);
}
Log("=== DigimonNOAccess Debug Log Started ===");
Log($"Time: {DateTime.Now}");
_initialized = true;
}
catch (Exception ex)
{
// Can't use DebugLogger.Warning here since initialization failed
System.Console.WriteLine($"[DigimonNOAccess] Failed to initialize debug logger: {ex.Message}");
}
}
public static void Log(string message)
{
if (!_initialized || string.IsNullOrEmpty(_logPath))
return;
try
{
lock (_lock)
{
using (var writer = new StreamWriter(_logPath, true))
{
writer.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] {message}");
}
}
}
catch
{
// Silently fail - don't want logging to break the mod
}
}
public static void Warning(string message)
{
Log($"[WARN] {message}");
}
public static void Error(string message)
{
Log($"[ERROR] {message}");
}
public static void LogSection(string title)
{
Log("");
Log($"=== {title} ===");
}
}
}