|
1
2
3
|
using NLog;
namespace HHECS.DAQHandle.Common.Utils
|
|
4
|
{
|
|
5
|
internal static class SystemLog
|
|
6
|
{
|
|
7
|
private static readonly object lockObj = new object();
|
|
8
9
|
private static readonly Logger _nlog = LogManager.GetCurrentClassLogger();
|
|
10
11
|
private static void Print(string message, LogType type = LogType.Info)
{
|
|
12
13
14
|
lock (lockObj)
{
Console.Write('[');
|
|
15
|
Console.ForegroundColor = type switch
|
|
16
|
{
|
|
17
18
19
20
21
22
|
LogType.Success => ConsoleColor.DarkGreen,
LogType.Info => ConsoleColor.DarkBlue,
LogType.Warn => ConsoleColor.DarkYellow,
LogType.Error => ConsoleColor.DarkRed,
_ => default
};
|
|
23
|
Console.Write($"{type}");
|
唐召明
authored
|
24
|
Console.ForegroundColor = ConsoleColor.Gray;
|
|
25
26
|
Console.Write(']');
Console.WriteLine($" {DateTime.Now} {message}");
|
|
27
28
29
30
31
32
33
34
35
|
if (type == LogType.Error)
{
_nlog.Error(message);
}
else
{
_nlog.Info(message);
}
|
|
36
|
}
|
|
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
}
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 enum LogType
{
|
|
57
|
Success,
|
|
58
59
60
61
62
|
Info,
Warn,
Error
}
}
|