-
Notifications
You must be signed in to change notification settings - Fork 4
/
LogEntry.cs
123 lines (118 loc) · 3.45 KB
/
LogEntry.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System;
using System.Collections.Generic;
using System.Windows.Media;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Documents;
using System.Windows;
using System.Diagnostics;
namespace RazzTools
{
public class LogEntry
{
public static Color NormalColor { get; set; } = Color.FromArgb(System.Drawing.SystemColors.WindowText.A, System.Drawing.SystemColors.WindowText.R, System.Drawing.SystemColors.WindowText.G, System.Drawing.SystemColors.WindowText.B);
public static Color SuccessColor { get; set; } = Color.FromRgb(50, 175, 50);
public static Color ErrorColor { get; set; } = Color.FromRgb(175, 50, 50);
public static Color WarningColor { get; set; } = Color.FromRgb(255, 170, 0);
private string message;
private LogEntryType logMessageType;
private DateTime timeStamp;
public string Message
{
get
{
return message;
}
}
public LogEntryType Type
{
get
{
return logMessageType;
}
}
public DateTime TimeStamp
{
get
{
return timeStamp;
}
}
public bool ShowTimeStamp { get; set; }
public Color Color
{
get
{
if (Type == LogEntryType.Success)
{
return SuccessColor;
}
else if (Type == LogEntryType.Error)
{
return ErrorColor;
}
else if (Type == LogEntryType.Warning)
{
return WarningColor;
}
return NormalColor;
}
}
public LogEntry(string msg, LogEntryType messageType)
{
message = msg;
logMessageType = messageType;
ShowTimeStamp = true;
timeStamp = DateTime.Now;
}
public LogEntry(string msg) : this(msg, LogEntryType.Normal)
{
}
override public string ToString()
{
return Message;
}
public static explicit operator Paragraph(LogEntry entry)
{
string msg = entry.Message;
if (entry.ShowTimeStamp)
{
msg = $"{entry.TimeStamp.ToString()}: {msg}";
}
Run run = new Run(msg);
run.Foreground = new SolidColorBrush(entry.Color);
Paragraph paragraph = new Paragraph(run);
paragraph.Margin = new Thickness(0);
return paragraph;
}
public static explicit operator Block(LogEntry logMessage)
{
return (Paragraph)logMessage;
}
}
public enum LogEntryType
{
Normal,
Success,
Error,
Warning
}
public class LoggedMessageEventArgs : EventArgs
{
private readonly LogEntry _logEntry;
public LoggedMessageEventArgs(string message, LogEntryType logtype)
{
_logEntry = new LogEntry(message,logtype);
}
public LoggedMessageEventArgs(string message) : this(message, LogEntryType.Normal) { }
public LoggedMessageEventArgs(LogEntry entry)
{
_logEntry = entry;
}
public LogEntry LogEntry
{
get { return _logEntry; }
}
}
}