-
Notifications
You must be signed in to change notification settings - Fork 1
/
Logger.cs
64 lines (58 loc) · 1.77 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
54
55
56
57
58
59
60
61
62
63
64
using System;
namespace ControlProgram
{
class Logger
{
//Logger levels, FATAL will stop the program
public enum Level
{
DEBUG,
INFO,
WARNING,
ERROR,
FATAL
}
private string system;
public Level minLogLevel;
//System is the subsystem name, minloglevel is the lowest level it will broadcast.
public Logger(string system, Level minLogLevel)
{
this.system = system;
this.minLogLevel = minLogLevel;
}
public void log(Level level, string message)
{
var color = new ConsoleColor();
switch (level)
{
case Level.DEBUG:
color = ConsoleColor.Yellow;
break;
case Level.INFO:
color = ConsoleColor.Cyan;
break;
case Level.ERROR:
color = ConsoleColor.Red;
break;
case Level.WARNING:
color = ConsoleColor.Magenta;
break;
case Level.FATAL:
color = ConsoleColor.DarkBlue;
break;
}
if (level >= minLogLevel)
{
Console.Write("[LOG][" + DateTime.Now.ToString("HH:mm:ss.fff") + "][");
Console.ForegroundColor = color;
Console.Write(level.ToString("g"));
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("][" + system + "]:: " + message);
if(level == Level.FATAL)
{
Environment.Exit(1);
}
}
}
}
}