-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConsoleLogger.cs
54 lines (52 loc) · 1.59 KB
/
ConsoleLogger.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
using System;
namespace alma.debugify
{
internal interface ILogger
{
void Verbose(string message);
void Debug(string message);
void Info(string message);
void Success(string message);
void Warning(string message);
void Error(string message);
}
internal class ConsoleLogger : ILogger
{
public void Verbose(string message)
{
WriteWithColor(message, ConsoleColor.DarkGray);
}
public void Debug(string message)
{
WriteWithColor(message, ConsoleColor.Gray);
}
public void Info(string message)
{
WriteWithColor(message, ConsoleColor.White);
}
public void Success(string message)
{
WriteWithColor(message, ConsoleColor.Green);
}
public void Warning(string message)
{
WriteWithColor(message, ConsoleColor.DarkYellow);
}
public void Error(string message)
{
WriteWithColor(message, ConsoleColor.Red);
}
private void WriteWithColor(string message, ConsoleColor? foreground = null, ConsoleColor? background = null)
{
var c = Console.ForegroundColor;
var b = Console.BackgroundColor;
if(foreground.HasValue)
Console.ForegroundColor = foreground.Value;
if(background.HasValue)
Console.BackgroundColor = background.Value;
Console.WriteLine(message);
Console.ForegroundColor = c;
Console.BackgroundColor = b;
}
}
}