This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathPluginTrace.cs
111 lines (87 loc) · 3.45 KB
/
PluginTrace.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
using System;
using System.Diagnostics;
using TShockAPI;
namespace Terraria.Plugins.Common {
public class PluginTrace {
public const ConsoleColor ConsoleErrorColor = ConsoleColor.Red;
public const ConsoleColor ConsoleWarningColor = ConsoleColor.Yellow;
public string TracePrefix { get; set; }
public PluginTrace(string tracePrefix) {
this.TracePrefix = tracePrefix;
}
public void WriteLine(string message, TraceLevel level = TraceLevel.Info) {
message = this.TracePrefix + message;
ConsoleColor oldColor = Console.ForegroundColor;
try {
switch (level) {
case TraceLevel.Error:
Console.ForegroundColor = PluginTrace.ConsoleErrorColor;
TShock.Log.Error(message);
break;
case TraceLevel.Warning:
Console.ForegroundColor = PluginTrace.ConsoleWarningColor;
TShock.Log.Warn(message);
break;
default:
TShock.Log.Info(message);
break;
}
Console.WriteLine(message);
} finally {
Console.ForegroundColor = oldColor;
}
}
public void WriteLineInfo(string format, params object[] args) {
this.WriteLine(string.Format(format, args));
}
public void WriteLineInfo(string format, object arg0, object arg1) {
this.WriteLine(string.Format(format, arg0, arg1));
}
public void WriteLineInfo(string format, object arg0) {
this.WriteLine(string.Format(format, arg0));
}
public void WriteLineInfo(string lineString) {
this.WriteLine(lineString);
}
public void WriteLineWarning(string format, params object[] args) {
this.WriteLine(string.Format(format, args), TraceLevel.Warning);
}
public void WriteLineWarning(string format, object arg0, object arg1) {
this.WriteLine(string.Format(format, arg0, arg1), TraceLevel.Warning);
}
public void WriteLineWarning(string format, object arg0) {
this.WriteLine(string.Format(format, arg0), TraceLevel.Warning);
}
public void WriteLineWarning(string lineString) {
this.WriteLine(lineString, TraceLevel.Warning);
}
public void WriteLineError(string format, params object[] args) {
this.WriteLine(string.Format(format, args), TraceLevel.Error);
}
public void WriteLineError(string format, object arg0, object arg1) {
this.WriteLine(string.Format(format, arg0, arg1), TraceLevel.Error);
}
public void WriteLineError(string format, object arg0) {
this.WriteLine(string.Format(format, arg0), TraceLevel.Error);
}
public void WriteLineError(string lineString) {
this.WriteLine(lineString, TraceLevel.Error);
}
[Conditional("Verbose")]
public void WriteLineVerbose(string format, params object[] args) {
this.WriteLine(string.Format(format, args), TraceLevel.Verbose);
}
[Conditional("Verbose")]
public void WriteLineVerbose(string format, object arg0, object arg1) {
this.WriteLine(string.Format(format, arg0, arg1), TraceLevel.Verbose);
}
[Conditional("Verbose")]
public void WriteLineVerbose(string format, object arg0) {
this.WriteLine(string.Format(format, arg0), TraceLevel.Verbose);
}
[Conditional("Verbose")]
public void WriteLineVerbose(string lineString) {
this.WriteLine(lineString, TraceLevel.Verbose);
}
}
}