-
Notifications
You must be signed in to change notification settings - Fork 525
/
ConsoleImpl.cs
66 lines (53 loc) · 2.01 KB
/
ConsoleImpl.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
55
56
57
58
59
60
61
62
63
64
65
66
using System;
namespace Paket.Bootstrapper
{
public static class ConsoleImpl
{
public static Verbosity Verbosity { get; set; }
public static bool IsTraceEnabled { get { return Verbosity >= Verbosity.Trace; } }
internal static void WriteError(string message, params object[] parameters)
{
WriteConsole(string.Format(message, parameters), ConsoleColor.Red, Verbosity.ErrorsOnly);
}
internal static void WriteError(string message)
{
WriteConsole(message, ConsoleColor.Red, Verbosity.ErrorsOnly);
}
internal static void WriteWarning(string message, params object[] parameters)
{
WriteConsole(string.Format(message, parameters), ConsoleColor.Yellow);
}
internal static void WriteWarning(string message)
{
WriteConsole(message, ConsoleColor.Yellow);
}
internal static void WriteInfo(string message, params object[] parameters)
{
WriteConsole(string.Format(message, parameters), Console.ForegroundColor);
}
internal static void WriteInfo(string message)
{
WriteConsole(message, Console.ForegroundColor);
}
internal static void WriteTrace(string message, params object[] parameters)
{
WriteConsole(string.Format(message, parameters), ConsoleColor.DarkGray, Verbosity.Trace);
}
internal static void WriteTrace(string message)
{
WriteConsole(message, ConsoleColor.DarkGray, Verbosity.Trace);
}
private static void WriteConsole(string message, ConsoleColor consoleColor, Verbosity minVerbosity = Verbosity.Normal)
{
if (Verbosity < minVerbosity)
{
return;
}
var oldColor = Console.ForegroundColor;
Console.ForegroundColor = consoleColor;
Console.WriteLine(message);
Console.ForegroundColor = oldColor;
}
}
}