SystemLog.cs
1.76 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
using NLog;
namespace HHECS.DAQHandle.Common.Utils
{
internal static class SystemLog
{
private static readonly object lockObj = new object();
private static readonly Logger _nlog = LogManager.GetCurrentClassLogger();
private static void Print(string message, LogType type = LogType.Info)
{
lock (lockObj)
{
Console.Write('[');
Console.ForegroundColor = type switch
{
LogType.Success => ConsoleColor.DarkGreen,
LogType.Info => ConsoleColor.DarkBlue,
LogType.Warn => ConsoleColor.DarkYellow,
LogType.Error => ConsoleColor.DarkRed,
_ => default
};
Console.Write($"{type}");
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write(']');
Console.WriteLine($" {DateTime.Now} {message}");
if (type == LogType.Error)
{
_nlog.Error(message);
}
else
{
_nlog.Info(message);
}
}
}
public static void PrintInfo(string message)
{
Print(message, LogType.Info);
}
public static void PrintWarn(string message)
{
Print(message, LogType.Warn);
}
public static void PrintError(string message)
{
Print(message, LogType.Error);
}
public static void PrintSuccess(string message)
{
Print(message, LogType.Success);
}
}
public enum LogType
{
Success,
Info,
Warn,
Error
}
}