-
Notifications
You must be signed in to change notification settings - Fork 7
/
Log.cs
66 lines (61 loc) · 2.29 KB
/
Log.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
65
66
using System;
using System.Runtime.CompilerServices;
namespace KP184
{
class Log
{
public enum Level
{
Debug,
Verbose,
Info,
Warning,
Error
};
static Level _log_level = Level.Info;
public static Level level
{
get
{
return _log_level;
}
set
{
_log_level = value;
Log.Debug($"Setting log level to {value}");
}
}
public static void Write(Level severity, object o, ConsoleColor color, [CallerMemberName]string tag = "", [CallerFilePath]string file = "", [CallerLineNumber]int line = 0)
{
if(severity >= level)
{
string now = DateTime.Now.ToString("HH:mm:ss.fff");
string text = $"{severity,-8} {now} {tag,-20}:{o}";
System.Diagnostics.Debug.WriteLine(text);
Console.ForegroundColor = color;
Console.WriteLine(text);
Console.ResetColor();
}
}
public static void Debug(object o, [CallerMemberName]string tag = "", [CallerFilePath]string file = "", [CallerLineNumber]int line = 0)
{
Write(Level.Debug, o, ConsoleColor.DarkGreen, tag, file, line);
}
public static void Verbose(object o, [CallerMemberName]string tag = "", [CallerFilePath]string file = "", [CallerLineNumber]int line = 0)
{
Write(Level.Verbose, o, ConsoleColor.Cyan, tag, file, line);
}
public static void Info(object o, [CallerMemberName]string tag = "", [CallerFilePath]string file = "", [CallerLineNumber]int line = 0)
{
Write(Level.Info, o, ConsoleColor.White, tag, file, line);
}
public static void Warning(object o, [CallerMemberName]string tag = "", [CallerFilePath]string file = "", [CallerLineNumber]int line = 0)
{
Write(Level.Warning, o, ConsoleColor.Yellow, tag, file, line);
}
public static void Error(object o, [CallerMemberName]string tag = "", [CallerFilePath]string file = "", [CallerLineNumber]int line = 0)
{
Write(Level.Error, o, ConsoleColor.Red, tag, file, line);
}
}
}