Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DelimitedListTraceListener.cs
Go to the documentation of this file.
3using System.IO;
4using System.Text;
5
6namespace System.Diagnostics;
7
9{
10 private string _delimiter = ";";
11
12 private string _secondaryDelim = ",";
13
14 private bool _initializedDelim;
15
16 public string Delimiter
17 {
18 get
19 {
20 lock (this)
21 {
23 {
24 if (base.Attributes.ContainsKey("delimiter"))
25 {
26 string text = base.Attributes["delimiter"];
27 if (!string.IsNullOrEmpty(text))
28 {
30 }
31 }
32 _initializedDelim = true;
33 }
34 }
35 return _delimiter;
36 }
37 set
38 {
39 if (value == null)
40 {
41 throw new ArgumentNullException("Delimiter");
42 }
43 if (value.Length == 0)
44 {
46 }
47 lock (this)
48 {
50 _initializedDelim = true;
51 }
52 if (_delimiter == ",")
53 {
54 _secondaryDelim = ";";
55 }
56 else
57 {
58 _secondaryDelim = ",";
59 }
60 }
61 }
62
64 : base(stream)
65 {
66 }
67
69 : base(stream, name)
70 {
71 }
72
74 : base(writer)
75 {
76 }
77
79 : base(writer, name)
80 {
81 }
82
83 public DelimitedListTraceListener(string? fileName)
84 : base(fileName)
85 {
86 }
87
88 public DelimitedListTraceListener(string? fileName, string? name)
89 : base(fileName, name)
90 {
91 }
92
93 protected override string[] GetSupportedAttributes()
94 {
95 return new string[1] { "delimiter" };
96 }
97
98 public override void TraceEvent(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, string? format, params object?[]? args)
99 {
100 if (base.Filter == null || base.Filter.ShouldTrace(eventCache, source, eventType, id, format, args, null, null))
101 {
102 WriteHeader(source, eventType, id);
103 if (args != null)
104 {
106 }
107 else
108 {
110 }
113 WriteFooter(eventCache);
114 }
115 }
116
117 public override void TraceEvent(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, string? message)
118 {
119 if (base.Filter == null || base.Filter.ShouldTrace(eventCache, source, eventType, id, message, null, null, null))
120 {
121 WriteHeader(source, eventType, id);
122 WriteEscaped(message);
125 WriteFooter(eventCache);
126 }
127 }
128
129 public override void TraceData(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, object? data)
130 {
131 if (base.Filter == null || base.Filter.ShouldTrace(eventCache, source, eventType, id, null, null, data, null))
132 {
133 WriteHeader(source, eventType, id);
135 WriteEscaped(data?.ToString());
137 WriteFooter(eventCache);
138 }
139 }
140
141 public override void TraceData(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, params object?[]? data)
142 {
143 if (base.Filter != null && !base.Filter.ShouldTrace(eventCache, source, eventType, id, null, null, null, data))
144 {
145 return;
146 }
147 WriteHeader(source, eventType, id);
149 if (data != null)
150 {
151 for (int i = 0; i < data.Length; i++)
152 {
153 if (i != 0)
154 {
156 }
157 WriteEscaped(data[i]?.ToString());
158 }
159 }
161 WriteFooter(eventCache);
162 }
163
164 private void WriteHeader(string source, TraceEventType eventType, int id)
165 {
168 Write(eventType.ToString());
172 }
173
174 private void WriteFooter(TraceEventCache eventCache)
175 {
176 if (eventCache != null)
177 {
178 if (IsEnabled(TraceOptions.ProcessId))
179 {
180 Write(eventCache.ProcessId.ToString(CultureInfo.InvariantCulture));
181 }
183 if (IsEnabled(TraceOptions.LogicalOperationStack))
184 {
186 }
188 if (IsEnabled(TraceOptions.ThreadId))
189 {
190 WriteEscaped(eventCache.ThreadId);
191 }
193 if (IsEnabled(TraceOptions.DateTime))
194 {
196 }
198 if (IsEnabled(TraceOptions.Timestamp))
199 {
200 Write(eventCache.Timestamp.ToString(CultureInfo.InvariantCulture));
201 }
203 if (IsEnabled(TraceOptions.Callstack))
204 {
205 WriteEscaped(eventCache.Callstack);
206 }
207 }
208 else
209 {
210 for (int i = 0; i < 5; i++)
211 {
213 }
214 }
215 WriteLine("");
216 }
217
218 private void WriteEscaped(string message)
219 {
220 if (!string.IsNullOrEmpty(message))
221 {
222 StringBuilder stringBuilder = new StringBuilder("\"");
223 EscapeMessage(message, stringBuilder);
224 stringBuilder.Append('"');
225 Write(stringBuilder.ToString());
226 }
227 }
228
229 private void WriteStackEscaped(Stack stack)
230 {
231 StringBuilder stringBuilder = new StringBuilder("\"");
232 bool flag = true;
233 foreach (object item in stack)
234 {
235 if (!flag)
236 {
237 stringBuilder.Append(", ");
238 }
239 else
240 {
241 flag = false;
242 }
243 string message = item?.ToString();
244 EscapeMessage(message, stringBuilder);
245 }
246 stringBuilder.Append('"');
247 Write(stringBuilder.ToString());
248 }
249
250 private void EscapeMessage(string message, StringBuilder sb)
251 {
252 if (!string.IsNullOrEmpty(message))
253 {
254 int num = 0;
255 int num2;
256 while ((num2 = message.IndexOf('"', num)) != -1)
257 {
258 sb.Append(message, num, num2 - num);
259 sb.Append("\"\"");
260 num = num2 + 1;
261 }
262 sb.Append(message, num, message.Length - num);
263 }
264 }
265}
override void TraceEvent(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, string? message)
override void TraceEvent(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, string? format, params object?[]? args)
override void TraceData(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, params object?[]? data)
void EscapeMessage(string message, StringBuilder sb)
void WriteHeader(string source, TraceEventType eventType, int id)
override void TraceData(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, object? data)
DelimitedListTraceListener(TextWriter writer, string? name)
static CultureInfo InvariantCulture
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Generic_ArgCantBeEmptyString
Definition SR.cs:14
Definition SR.cs:7
override string ToString()
StringBuilder Append(char value, int repeatCount)
override string ToString()
Definition DateTime.cs:1109