Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TraceListener.cs
Go to the documentation of this file.
6
7namespace System.Diagnostics;
8
10{
11 private int _indentLevel;
12
13 private int _indentSize = 4;
14
16
17 private bool _needIndent = true;
18
20
21 private string _listenerName;
22
24
26 {
27 get
28 {
29 if (_attributes == null)
30 {
32 }
33 return _attributes;
34 }
35 }
36
37 public virtual string Name
38 {
39 get
40 {
41 return _listenerName ?? "";
42 }
43 [param: AllowNull]
44 set
45 {
47 }
48 }
49
50 public virtual bool IsThreadSafe => false;
51
52 public int IndentLevel
53 {
54 get
55 {
56 return _indentLevel;
57 }
58 set
59 {
60 _indentLevel = ((value >= 0) ? value : 0);
61 }
62 }
63
64 public int IndentSize
65 {
66 get
67 {
68 return _indentSize;
69 }
70 set
71 {
72 if (value < 0)
73 {
75 }
77 }
78 }
79
81 {
82 get
83 {
84 return _filter;
85 }
86 set
87 {
88 _filter = value;
89 }
90 }
91
92 protected bool NeedIndent
93 {
94 get
95 {
96 return _needIndent;
97 }
98 set
99 {
101 }
102 }
103
105 {
106 get
107 {
108 return _traceOptions;
109 }
110 set
111 {
112 if ((int)value >> 6 != 0)
113 {
114 throw new ArgumentOutOfRangeException("value");
115 }
117 }
118 }
119
120 protected TraceListener()
121 {
122 }
123
124 protected TraceListener(string? name)
125 {
126 _listenerName = name;
127 }
128
129 public void Dispose()
130 {
131 Dispose(disposing: true);
132 GC.SuppressFinalize(this);
133 }
134
135 protected virtual void Dispose(bool disposing)
136 {
137 }
138
139 public virtual void Flush()
140 {
141 }
142
143 public virtual void Close()
144 {
145 }
146
147 protected internal virtual string[]? GetSupportedAttributes()
148 {
149 return null;
150 }
151
152 public virtual void TraceTransfer(TraceEventCache? eventCache, string source, int id, string? message, Guid relatedActivityId)
153 {
154 IFormatProvider formatProvider = null;
155 IFormatProvider provider = formatProvider;
156 Span<char> initialBuffer = stackalloc char[256];
157 DefaultInterpolatedStringHandler handler = new DefaultInterpolatedStringHandler(20, 2, formatProvider, initialBuffer);
158 handler.AppendFormatted(message);
159 handler.AppendLiteral(", relatedActivityId=");
160 handler.AppendFormatted(relatedActivityId);
161 TraceEvent(eventCache, source, TraceEventType.Transfer, id, string.Create(provider, initialBuffer, ref handler));
162 }
163
164 public virtual void Fail(string? message)
165 {
166 Fail(message, null);
167 }
168
169 public virtual void Fail(string? message, string? detailMessage)
170 {
171 WriteLine((detailMessage == null) ? (System.SR.TraceListenerFail + " " + message) : $"{System.SR.TraceListenerFail} {message} {detailMessage}");
172 }
173
174 public abstract void Write(string? message);
175
176 public virtual void Write(object? o)
177 {
178 if ((Filter == null || Filter.ShouldTrace(null, "", TraceEventType.Verbose, 0, null, null, o)) && o != null)
179 {
180 Write(o.ToString());
181 }
182 }
183
184 public virtual void Write(string? message, string? category)
185 {
186 if (Filter == null || Filter.ShouldTrace(null, "", TraceEventType.Verbose, 0, message))
187 {
188 if (category == null)
189 {
190 Write(message);
191 }
192 else
193 {
194 Write(category + ": " + ((message == null) ? string.Empty : message));
195 }
196 }
197 }
198
199 public virtual void Write(object? o, string? category)
200 {
201 if (Filter == null || Filter.ShouldTrace(null, "", TraceEventType.Verbose, 0, category, null, o))
202 {
203 if (category == null)
204 {
205 Write(o);
206 }
207 else
208 {
209 Write((o == null) ? "" : o.ToString(), category);
210 }
211 }
212 }
213
214 protected virtual void WriteIndent()
215 {
216 NeedIndent = false;
217 for (int i = 0; i < _indentLevel; i++)
218 {
219 if (_indentSize == 4)
220 {
221 Write(" ");
222 continue;
223 }
224 for (int j = 0; j < _indentSize; j++)
225 {
226 Write(" ");
227 }
228 }
229 }
230
231 public abstract void WriteLine(string? message);
232
233 public virtual void WriteLine(object? o)
234 {
235 if (Filter == null || Filter.ShouldTrace(null, "", TraceEventType.Verbose, 0, null, null, o))
236 {
237 WriteLine((o == null) ? "" : o.ToString());
238 }
239 }
240
241 public virtual void WriteLine(string? message, string? category)
242 {
243 if (Filter == null || Filter.ShouldTrace(null, "", TraceEventType.Verbose, 0, message))
244 {
245 if (category == null)
246 {
247 WriteLine(message);
248 }
249 else
250 {
251 WriteLine(category + ": " + ((message == null) ? string.Empty : message));
252 }
253 }
254 }
255
256 public virtual void WriteLine(object? o, string? category)
257 {
258 if (Filter == null || Filter.ShouldTrace(null, "", TraceEventType.Verbose, 0, category, null, o))
259 {
260 WriteLine((o == null) ? "" : o.ToString(), category);
261 }
262 }
263
264 public virtual void TraceData(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, object? data)
265 {
266 if (Filter == null || Filter.ShouldTrace(eventCache, source, eventType, id, null, null, data))
267 {
268 WriteHeader(source, eventType, id);
269 string message = string.Empty;
270 if (data != null)
271 {
272 message = data.ToString();
273 }
274 WriteLine(message);
275 WriteFooter(eventCache);
276 }
277 }
278
279 public virtual void TraceData(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, params object?[]? data)
280 {
281 if (Filter == null || Filter.ShouldTrace(eventCache, source, eventType, id, null, null, null, data))
282 {
283 WriteHeader(source, eventType, id);
284 WriteLine((data != null) ? string.Join(", ", data) : string.Empty);
285 WriteFooter(eventCache);
286 }
287 }
288
289 public virtual void TraceEvent(TraceEventCache? eventCache, string source, TraceEventType eventType, int id)
290 {
291 TraceEvent(eventCache, source, eventType, id, string.Empty);
292 }
293
294 public virtual void TraceEvent(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, string? message)
295 {
296 if (Filter == null || Filter.ShouldTrace(eventCache, source, eventType, id, message))
297 {
298 WriteHeader(source, eventType, id);
299 WriteLine(message);
300 WriteFooter(eventCache);
301 }
302 }
303
304 public virtual void TraceEvent(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, string? format, params object?[]? args)
305 {
306 if (Filter == null || Filter.ShouldTrace(eventCache, source, eventType, id, format, args))
307 {
308 WriteHeader(source, eventType, id);
309 if (args != null)
310 {
312 }
313 else
314 {
316 }
317 WriteFooter(eventCache);
318 }
319 }
320
321 private void WriteHeader(string source, TraceEventType eventType, int id)
322 {
324 IFormatProvider provider = invariantCulture;
325 Span<char> initialBuffer = stackalloc char[256];
326 DefaultInterpolatedStringHandler handler = new DefaultInterpolatedStringHandler(6, 3, invariantCulture, initialBuffer);
327 handler.AppendFormatted(source);
328 handler.AppendLiteral(" ");
329 handler.AppendFormatted(eventType);
330 handler.AppendLiteral(": ");
331 handler.AppendFormatted(id);
332 handler.AppendLiteral(" : ");
333 Write(string.Create(provider, initialBuffer, ref handler));
334 }
335
336 private void WriteFooter(TraceEventCache eventCache)
337 {
338 if (eventCache == null)
339 {
340 return;
341 }
342 _indentLevel++;
343 if (IsEnabled(TraceOptions.ProcessId))
344 {
345 WriteLine("ProcessId=" + eventCache.ProcessId);
346 }
347 if (IsEnabled(TraceOptions.LogicalOperationStack))
348 {
349 Write("LogicalOperationStack=");
350 Stack logicalOperationStack = eventCache.LogicalOperationStack;
351 bool flag = true;
352 foreach (object item in logicalOperationStack)
353 {
354 if (!flag)
355 {
356 Write(", ");
357 }
358 else
359 {
360 flag = false;
361 }
362 Write(item.ToString());
363 }
364 WriteLine(string.Empty);
365 }
366 Span<char> span = stackalloc char[128];
367 if (IsEnabled(TraceOptions.ThreadId))
368 {
369 WriteLine("ThreadId=" + eventCache.ThreadId);
370 }
371 if (IsEnabled(TraceOptions.DateTime))
372 {
373 IFormatProvider formatProvider = null;
374 IFormatProvider provider = formatProvider;
375 Span<char> span2 = span;
376 Span<char> initialBuffer = span2;
377 DefaultInterpolatedStringHandler handler = new DefaultInterpolatedStringHandler(9, 1, formatProvider, span2);
378 handler.AppendLiteral("DateTime=");
379 handler.AppendFormatted(eventCache.DateTime, "o");
380 WriteLine(string.Create(provider, initialBuffer, ref handler));
381 }
382 if (IsEnabled(TraceOptions.Timestamp))
383 {
384 IFormatProvider formatProvider = null;
385 IFormatProvider provider2 = formatProvider;
386 Span<char> span2 = span;
387 Span<char> initialBuffer2 = span2;
388 DefaultInterpolatedStringHandler handler2 = new DefaultInterpolatedStringHandler(10, 1, formatProvider, span2);
389 handler2.AppendLiteral("Timestamp=");
390 handler2.AppendFormatted(eventCache.Timestamp);
391 WriteLine(string.Create(provider2, initialBuffer2, ref handler2));
392 }
393 if (IsEnabled(TraceOptions.Callstack))
394 {
395 WriteLine("Callstack=" + eventCache.Callstack);
396 }
397 _indentLevel--;
398 }
399
400 internal bool IsEnabled(TraceOptions opts)
401 {
402 return (opts & TraceOutputOptions) != 0;
403 }
404}
bool ShouldTrace(TraceEventCache? cache, string source, TraceEventType eventType, int id, string? formatOrMessage, object?[]? args, object? data1, object?[]? data)
virtual void WriteLine(object? o)
virtual void Fail(string? message, string? detailMessage)
virtual void Fail(string? message)
void WriteLine(string? message)
void Write(string? message)
virtual void TraceTransfer(TraceEventCache? eventCache, string source, int id, string? message, Guid relatedActivityId)
virtual void WriteLine(string? message, string? category)
virtual ? string[] GetSupportedAttributes()
bool IsEnabled(TraceOptions opts)
virtual void TraceEvent(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, string? format, params object?[]? args)
virtual void TraceData(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, object? data)
virtual void Write(object? o, string? category)
virtual void WriteLine(object? o, string? category)
void WriteFooter(TraceEventCache eventCache)
virtual void TraceEvent(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, string? message)
virtual void Dispose(bool disposing)
void WriteHeader(string source, TraceEventType eventType, int id)
virtual void Write(string? message, string? category)
virtual void TraceData(TraceEventCache? eventCache, string source, TraceEventType eventType, int id, params object?[]? data)
virtual void Write(object? o)
virtual void TraceEvent(TraceEventCache? eventCache, string source, TraceEventType eventType, int id)
static void SuppressFinalize(object obj)
Definition GC.cs:202
Definition GC.cs:8
static CultureInfo InvariantCulture
static string TraceListenerIndentSize
Definition SR.cs:20
static string TraceListenerFail
Definition SR.cs:18
Definition SR.cs:7