This repository has been archived by the owner on Dec 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.cs
53 lines (51 loc) · 1.53 KB
/
Logger.cs
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
using System.Diagnostics;
namespace Tptpd
{
static class Logger
{
[Flags]
public enum LEVELS
{
FATAL = 0x1,
ERROR = 0x3,
INFO = 0x5,
TRACE = 0x9
}
static LEVELS Level;
public static void SetLevel(LEVELS set) { Level = set; }
public static void Trace(string msg)
{
if (Level.HasFlag(LEVELS.TRACE))
{
string formatted = $"[{Thread.CurrentThread.ManagedThreadId}] INFO {msg}";
Console.WriteLine(formatted);
Debug.WriteLine(formatted);
}
}
public static void Info(string msg)
{
if (Level.HasFlag(LEVELS.INFO))
{
string formatted = $"[{Thread.CurrentThread.ManagedThreadId}] INFO {msg}";
Console.WriteLine(formatted);
Debug.WriteLine(formatted);
}
}
public static void Error(string msg)
{
if (Level.HasFlag(LEVELS.ERROR))
{
string formatted = $"[{Thread.CurrentThread.ManagedThreadId}] ERROR {msg}";
Console.WriteLine(formatted);
Debug.WriteLine(formatted);
}
}
public static void Fatal(string msg, Exception e)
{
string formatted = $"[{Thread.CurrentThread.ManagedThreadId}] FATAL {msg}";
Console.WriteLine(formatted);
Debug.WriteLine(formatted);
throw e;
}
}
}