-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLogger.cs
More file actions
40 lines (33 loc) · 1.14 KB
/
Copy pathLogger.cs
File metadata and controls
40 lines (33 loc) · 1.14 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
using System;
using System.IO;
namespace GameSnapPlugin
{
public enum LogType { Move, Learn, Fallback, Error, Info }
public class GameSnapLogger
{
private readonly string _logPath;
private readonly object _lock = new object();
public GameSnapLogger(string pluginDataPath)
{
_logPath = Path.Combine(pluginDataPath, "gamesnap.log");
}
public void Write(LogType type, string message)
{
var prefix = type switch
{
LogType.Move => "✔ MOVED",
LogType.Learn => "🧠 LEARNED",
LogType.Fallback => "⚠ FALLBACK",
LogType.Error => "❌ ERROR",
_ => "LOG"
};
var line = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {prefix}\n{message}\n";
lock (_lock)
{
File.AppendAllText(_logPath, line, System.Text.Encoding.UTF8);
}
}
public void Info(string message) => Write(LogType.Info, message);
public void Error(string message) => Write(LogType.Error, message);
}
}