-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
104 lines (93 loc) · 3.13 KB
/
Program.cs
File metadata and controls
104 lines (93 loc) · 3.13 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
namespace Singleton
{
public enum LogLevel
{
Error,
Warning,
Comment
}
public class SingletonLogger
{
static SingletonLogger instance;
private SingletonLogger()
{
}
public static SingletonLogger Instance()
{
if (instance == null)
{
instance = new SingletonLogger();
}
return instance;
}
public void Log(Singleton.LogLevel level, string message)
{
switch(level)
{
case LogLevel.Error:
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(message);
Console.ResetColor();
Environment.Exit(1);
break;
case LogLevel.Warning:
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(message);
Console.ResetColor();
break;
case LogLevel.Comment:
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(message);
break;
default:
break;
}
}
}
public static class StaticLogger
{
static StaticLogger()
{
}
public static void Log(Singleton.LogLevel level, string message)
{
switch(level)
{
case LogLevel.Error:
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(message);
Console.ResetColor();
Environment.Exit(1);
break;
case LogLevel.Warning:
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(message);
Console.ResetColor();
break;
case LogLevel.Comment:
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(message);
break;
default:
break;
}
}
}
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Creating Singleton logger...");
SingletonLogger singletonLogger = SingletonLogger.Instance();
singletonLogger.Log(LogLevel.Comment, "Test singleton comment...");
singletonLogger.Log(LogLevel.Warning, "Test singleton warning...");
//singletonLogger.Log(LogLevel.Error, "Test singleton error...");
singletonLogger.Log(LogLevel.Comment, "Test singleton comment again...");
Console.WriteLine("Using Static logger...");
StaticLogger.Log(LogLevel.Comment, "Test static comment...");
StaticLogger.Log(LogLevel.Warning, "Test static warning...");
StaticLogger.Log(LogLevel.Error, "Test static error...");
StaticLogger.Log(LogLevel.Comment, "Test static comment again...");
}
}
}