-
Notifications
You must be signed in to change notification settings - Fork 1
/
Log.cs
70 lines (60 loc) · 1.74 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
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
using System;
namespace BTD_Backend
{
/// <summary>
/// Which medium do you want the message to output to?
/// </summary>
public enum OutputType
{
Console,
MsgBox,
Both
}
public class Log
{
#region Properties
/// <summary>
/// Singleton instance of this class
/// </summary>
private static Log instance;
public static Log Instance
{
get
{
if (instance == null)
instance = new Log();
return instance;
}
}
#endregion
#region Events
public static event EventHandler<LogEvents> MessageLogged;
public class LogEvents : EventArgs
{
public string Message { get; set; }
public OutputType Output { get; set; }
}
/// <summary>
/// When a message has been sent to the Output() function
/// </summary>
/// <param name="e">LogEvent args containing the output message</param>
public void OnMessageLogged(LogEvents e)
{
EventHandler<LogEvents> handler = MessageLogged;
if (handler != null)
handler(this, e);
}
#endregion
/// <summary>
/// Passes message to OnMessageLogged for Event Handling.
/// </summary>
/// <param name="text">Message to output to user</param>
public static void Output(string text, OutputType output = OutputType.Console)
{
LogEvents args = new LogEvents();
args.Output = output;
args.Message = ">> " + text + Environment.NewLine;
Instance.OnMessageLogged(args);
}
}
}