-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.cs
45 lines (41 loc) · 1.42 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HueLightDimmer
{
//Simple logging class to avoid using a logger since it adds unneeded complexity
internal static class Logger
{
internal static void Log(LogLevel level, string message)
{
var curColor = Console.ForegroundColor;
Console.ForegroundColor = GetLogColor(level);
Console.WriteLine($"[{level.ToString()[0]}][{DateTime.Now}] {message}");
Console.ForegroundColor = curColor;
}
internal static void Debug(string message)
=> Log(LogLevel.Debug, message);
internal static void Info(string message)
=> Log(LogLevel.Info, message);
internal static void Error(string message)
=> Log(LogLevel.Error, message);
internal static void Error(Exception ex, string message)
=> Error($"({ex.GetType().Name}) {message}: {ex.Message}");
private static ConsoleColor GetLogColor(LogLevel logLevel)
=> logLevel switch
{
LogLevel.Debug => ConsoleColor.Gray,
LogLevel.Info => ConsoleColor.Blue,
LogLevel.Error => ConsoleColor.Red,
_ => ConsoleColor.White
};
}
internal enum LogLevel
{
Debug = 0,
Info = 1,
Error = 2
}
}