-
Notifications
You must be signed in to change notification settings - Fork 0
/
Log.cs
44 lines (38 loc) · 1.14 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSMMon.ConsoleTool
{
class Log
{
static readonly ConsoleColor OriginalConsoleForegroundColor = Console.ForegroundColor;
public static void WriteLog(LogLevel level, string messageTemplate, params object[] args)
{
string message = string.Format(messageTemplate, args);
DateTime now = DateTime.Now;
if (level == LogLevel.Error)
{
Console.ForegroundColor = ConsoleColor.Red;
}
else if (level == LogLevel.OK)
{
Console.ForegroundColor = ConsoleColor.Green;
}
else if (level == LogLevel.High)
{
Console.ForegroundColor = ConsoleColor.White;
}
Console.WriteLine("[{0}] {1}", now.ToLogDateString(), message);
// reset console foreground color
Console.ForegroundColor = OriginalConsoleForegroundColor;
}
}
enum LogLevel
{
Verbose,
High,
OK,
Error,
}
}