Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TraceInternal.cs
Go to the documentation of this file.
2
3namespace System.Diagnostics;
4
5internal static class TraceInternal
6{
7 private sealed class TraceProvider : DebugProvider
8 {
9 public override void Fail(string message, string detailMessage)
10 {
11 TraceInternal.Fail(message, detailMessage);
12 }
13
14 public override void OnIndentLevelChanged(int indentLevel)
15 {
16 lock (critSec)
17 {
18 foreach (TraceListener listener in Listeners)
19 {
20 listener.IndentLevel = indentLevel;
21 }
22 }
23 }
24
25 public override void OnIndentSizeChanged(int indentSize)
26 {
27 lock (critSec)
28 {
29 foreach (TraceListener listener in Listeners)
30 {
31 listener.IndentSize = indentSize;
32 }
33 }
34 }
35
36 public override void Write(string message)
37 {
38 TraceInternal.Write(message);
39 }
40
41 public override void WriteLine(string message)
42 {
43 TraceInternal.WriteLine(message);
44 }
45 }
46
47 private static volatile string s_appName;
48
49 private static volatile TraceListenerCollection s_listeners;
50
51 private static volatile bool s_autoFlush;
52
53 private static volatile bool s_useGlobalLock;
54
55 private static volatile bool s_settingsInitialized;
56
57 internal static readonly object critSec = new object();
58
60 {
61 get
62 {
64 if (s_listeners == null)
65 {
66 lock (critSec)
67 {
68 if (s_listeners == null)
69 {
72 TraceListener traceListener = new DefaultTraceListener();
73 traceListener.IndentLevel = Debug.IndentLevel;
74 traceListener.IndentSize = Debug.IndentSize;
75 s_listeners.Add(traceListener);
76 }
77 }
78 }
79 return s_listeners;
80 }
81 }
82
83 internal static string AppName
84 {
85 get
86 {
87 if (s_appName == null)
88 {
89 s_appName = Assembly.GetEntryAssembly()?.GetName().Name ?? string.Empty;
90 }
91 return s_appName;
92 }
93 }
94
95 public static bool AutoFlush
96 {
97 get
98 {
100 return s_autoFlush;
101 }
102 set
103 {
106 }
107 }
108
109 public static bool UseGlobalLock
110 {
111 get
112 {
114 return s_useGlobalLock;
115 }
116 set
117 {
120 }
121 }
122
123 public static int IndentLevel
124 {
125 get
126 {
127 return Debug.IndentLevel;
128 }
129 set
130 {
131 Debug.IndentLevel = value;
132 }
133 }
134
135 public static int IndentSize
136 {
137 get
138 {
139 return Debug.IndentSize;
140 }
141 set
142 {
143 Debug.IndentSize = value;
144 }
145 }
146
147 public static void Indent()
148 {
150 }
151
152 public static void Unindent()
153 {
155 }
156
157 public static void Flush()
158 {
159 if (s_listeners == null)
160 {
161 return;
162 }
163 if (UseGlobalLock)
164 {
165 lock (critSec)
166 {
167 foreach (TraceListener listener in Listeners)
168 {
169 listener.Flush();
170 }
171 return;
172 }
173 }
174 foreach (TraceListener listener2 in Listeners)
175 {
176 if (!listener2.IsThreadSafe)
177 {
178 lock (listener2)
179 {
180 listener2.Flush();
181 }
182 }
183 else
184 {
185 listener2.Flush();
186 }
187 }
188 }
189
190 public static void Close()
191 {
192 if (s_listeners == null)
193 {
194 return;
195 }
196 lock (critSec)
197 {
198 foreach (TraceListener listener in Listeners)
199 {
200 listener.Close();
201 }
202 }
203 }
204
205 public static void Assert(bool condition)
206 {
207 if (!condition)
208 {
209 Fail(string.Empty);
210 }
211 }
212
213 public static void Assert(bool condition, string message)
214 {
215 if (!condition)
216 {
217 Fail(message);
218 }
219 }
220
221 public static void Assert(bool condition, string message, string detailMessage)
222 {
223 if (!condition)
224 {
225 Fail(message, detailMessage);
226 }
227 }
228
229 public static void Fail(string message)
230 {
231 if (UseGlobalLock)
232 {
233 lock (critSec)
234 {
235 foreach (TraceListener listener in Listeners)
236 {
237 listener.Fail(message);
238 if (AutoFlush)
239 {
240 listener.Flush();
241 }
242 }
243 return;
244 }
245 }
246 foreach (TraceListener listener2 in Listeners)
247 {
248 if (!listener2.IsThreadSafe)
249 {
250 lock (listener2)
251 {
252 listener2.Fail(message);
253 if (AutoFlush)
254 {
255 listener2.Flush();
256 }
257 }
258 }
259 else
260 {
261 listener2.Fail(message);
262 if (AutoFlush)
263 {
264 listener2.Flush();
265 }
266 }
267 }
268 }
269
270 public static void Fail(string message, string detailMessage)
271 {
272 if (UseGlobalLock)
273 {
274 lock (critSec)
275 {
276 foreach (TraceListener listener in Listeners)
277 {
278 listener.Fail(message, detailMessage);
279 if (AutoFlush)
280 {
281 listener.Flush();
282 }
283 }
284 return;
285 }
286 }
287 foreach (TraceListener listener2 in Listeners)
288 {
289 if (!listener2.IsThreadSafe)
290 {
291 lock (listener2)
292 {
293 listener2.Fail(message, detailMessage);
294 if (AutoFlush)
295 {
296 listener2.Flush();
297 }
298 }
299 }
300 else
301 {
302 listener2.Fail(message, detailMessage);
303 if (AutoFlush)
304 {
305 listener2.Flush();
306 }
307 }
308 }
309 }
310
311 private static void InitializeSettings()
312 {
314 {
315 return;
316 }
317 lock (critSec)
318 {
320 {
324 }
325 }
326 }
327
328 internal static void Refresh()
329 {
330 lock (critSec)
331 {
332 s_settingsInitialized = false;
333 s_listeners = null;
334 Debug.IndentSize = DiagnosticsConfiguration.IndentSize;
335 }
337 }
338
339 public static void TraceEvent(TraceEventType eventType, int id, string format, params object[] args)
340 {
341 TraceEventCache eventCache = new TraceEventCache();
342 if (UseGlobalLock)
343 {
344 lock (critSec)
345 {
346 if (args == null)
347 {
348 foreach (TraceListener listener in Listeners)
349 {
350 listener.TraceEvent(eventCache, AppName, eventType, id, format);
351 if (AutoFlush)
352 {
353 listener.Flush();
354 }
355 }
356 return;
357 }
358 foreach (TraceListener listener2 in Listeners)
359 {
360 listener2.TraceEvent(eventCache, AppName, eventType, id, format, args);
361 if (AutoFlush)
362 {
363 listener2.Flush();
364 }
365 }
366 return;
367 }
368 }
369 if (args == null)
370 {
371 foreach (TraceListener listener3 in Listeners)
372 {
373 if (!listener3.IsThreadSafe)
374 {
375 lock (listener3)
376 {
377 listener3.TraceEvent(eventCache, AppName, eventType, id, format);
378 if (AutoFlush)
379 {
380 listener3.Flush();
381 }
382 }
383 }
384 else
385 {
386 listener3.TraceEvent(eventCache, AppName, eventType, id, format);
387 if (AutoFlush)
388 {
389 listener3.Flush();
390 }
391 }
392 }
393 return;
394 }
395 foreach (TraceListener listener4 in Listeners)
396 {
397 if (!listener4.IsThreadSafe)
398 {
399 lock (listener4)
400 {
401 listener4.TraceEvent(eventCache, AppName, eventType, id, format, args);
402 if (AutoFlush)
403 {
404 listener4.Flush();
405 }
406 }
407 }
408 else
409 {
410 listener4.TraceEvent(eventCache, AppName, eventType, id, format, args);
411 if (AutoFlush)
412 {
413 listener4.Flush();
414 }
415 }
416 }
417 }
418
419 public static void Write(string message)
420 {
421 if (UseGlobalLock)
422 {
423 lock (critSec)
424 {
425 foreach (TraceListener listener in Listeners)
426 {
427 listener.Write(message);
428 if (AutoFlush)
429 {
430 listener.Flush();
431 }
432 }
433 return;
434 }
435 }
436 foreach (TraceListener listener2 in Listeners)
437 {
438 if (!listener2.IsThreadSafe)
439 {
440 lock (listener2)
441 {
442 listener2.Write(message);
443 if (AutoFlush)
444 {
445 listener2.Flush();
446 }
447 }
448 }
449 else
450 {
451 listener2.Write(message);
452 if (AutoFlush)
453 {
454 listener2.Flush();
455 }
456 }
457 }
458 }
459
460 public static void Write(object value)
461 {
462 if (UseGlobalLock)
463 {
464 lock (critSec)
465 {
466 foreach (TraceListener listener in Listeners)
467 {
468 listener.Write(value);
469 if (AutoFlush)
470 {
471 listener.Flush();
472 }
473 }
474 return;
475 }
476 }
477 foreach (TraceListener listener2 in Listeners)
478 {
479 if (!listener2.IsThreadSafe)
480 {
481 lock (listener2)
482 {
483 listener2.Write(value);
484 if (AutoFlush)
485 {
486 listener2.Flush();
487 }
488 }
489 }
490 else
491 {
492 listener2.Write(value);
493 if (AutoFlush)
494 {
495 listener2.Flush();
496 }
497 }
498 }
499 }
500
501 public static void Write(string message, string category)
502 {
503 if (UseGlobalLock)
504 {
505 lock (critSec)
506 {
507 foreach (TraceListener listener in Listeners)
508 {
509 listener.Write(message, category);
510 if (AutoFlush)
511 {
512 listener.Flush();
513 }
514 }
515 return;
516 }
517 }
518 foreach (TraceListener listener2 in Listeners)
519 {
520 if (!listener2.IsThreadSafe)
521 {
522 lock (listener2)
523 {
524 listener2.Write(message, category);
525 if (AutoFlush)
526 {
527 listener2.Flush();
528 }
529 }
530 }
531 else
532 {
533 listener2.Write(message, category);
534 if (AutoFlush)
535 {
536 listener2.Flush();
537 }
538 }
539 }
540 }
541
542 public static void Write(object value, string category)
543 {
544 if (UseGlobalLock)
545 {
546 lock (critSec)
547 {
548 foreach (TraceListener listener in Listeners)
549 {
550 listener.Write(value, category);
551 if (AutoFlush)
552 {
553 listener.Flush();
554 }
555 }
556 return;
557 }
558 }
559 foreach (TraceListener listener2 in Listeners)
560 {
561 if (!listener2.IsThreadSafe)
562 {
563 lock (listener2)
564 {
565 listener2.Write(value, category);
566 if (AutoFlush)
567 {
568 listener2.Flush();
569 }
570 }
571 }
572 else
573 {
574 listener2.Write(value, category);
575 if (AutoFlush)
576 {
577 listener2.Flush();
578 }
579 }
580 }
581 }
582
583 public static void WriteLine(string message)
584 {
585 if (UseGlobalLock)
586 {
587 lock (critSec)
588 {
589 foreach (TraceListener listener in Listeners)
590 {
591 listener.WriteLine(message);
592 if (AutoFlush)
593 {
594 listener.Flush();
595 }
596 }
597 return;
598 }
599 }
600 foreach (TraceListener listener2 in Listeners)
601 {
602 if (!listener2.IsThreadSafe)
603 {
604 lock (listener2)
605 {
606 listener2.WriteLine(message);
607 if (AutoFlush)
608 {
609 listener2.Flush();
610 }
611 }
612 }
613 else
614 {
615 listener2.WriteLine(message);
616 if (AutoFlush)
617 {
618 listener2.Flush();
619 }
620 }
621 }
622 }
623
624 public static void WriteLine(object value)
625 {
626 if (UseGlobalLock)
627 {
628 lock (critSec)
629 {
630 foreach (TraceListener listener in Listeners)
631 {
632 listener.WriteLine(value);
633 if (AutoFlush)
634 {
635 listener.Flush();
636 }
637 }
638 return;
639 }
640 }
641 foreach (TraceListener listener2 in Listeners)
642 {
643 if (!listener2.IsThreadSafe)
644 {
645 lock (listener2)
646 {
647 listener2.WriteLine(value);
648 if (AutoFlush)
649 {
650 listener2.Flush();
651 }
652 }
653 }
654 else
655 {
656 listener2.WriteLine(value);
657 if (AutoFlush)
658 {
659 listener2.Flush();
660 }
661 }
662 }
663 }
664
665 public static void WriteLine(string message, string category)
666 {
667 if (UseGlobalLock)
668 {
669 lock (critSec)
670 {
671 foreach (TraceListener listener in Listeners)
672 {
673 listener.WriteLine(message, category);
674 if (AutoFlush)
675 {
676 listener.Flush();
677 }
678 }
679 return;
680 }
681 }
682 foreach (TraceListener listener2 in Listeners)
683 {
684 if (!listener2.IsThreadSafe)
685 {
686 lock (listener2)
687 {
688 listener2.WriteLine(message, category);
689 if (AutoFlush)
690 {
691 listener2.Flush();
692 }
693 }
694 }
695 else
696 {
697 listener2.WriteLine(message, category);
698 if (AutoFlush)
699 {
700 listener2.Flush();
701 }
702 }
703 }
704 }
705
706 public static void WriteLine(object value, string category)
707 {
708 if (UseGlobalLock)
709 {
710 lock (critSec)
711 {
712 foreach (TraceListener listener in Listeners)
713 {
714 listener.WriteLine(value, category);
715 if (AutoFlush)
716 {
717 listener.Flush();
718 }
719 }
720 return;
721 }
722 }
723 foreach (TraceListener listener2 in Listeners)
724 {
725 if (!listener2.IsThreadSafe)
726 {
727 lock (listener2)
728 {
729 listener2.WriteLine(value, category);
730 if (AutoFlush)
731 {
732 listener2.Flush();
733 }
734 }
735 }
736 else
737 {
738 listener2.WriteLine(value, category);
739 if (AutoFlush)
740 {
741 listener2.Flush();
742 }
743 }
744 }
745 }
746
747 public static void WriteIf(bool condition, string message)
748 {
749 if (condition)
750 {
751 Write(message);
752 }
753 }
754
755 public static void WriteIf(bool condition, object value)
756 {
757 if (condition)
758 {
759 Write(value);
760 }
761 }
762
763 public static void WriteIf(bool condition, string message, string category)
764 {
765 if (condition)
766 {
767 Write(message, category);
768 }
769 }
770
771 public static void WriteIf(bool condition, object value, string category)
772 {
773 if (condition)
774 {
775 Write(value, category);
776 }
777 }
778
779 public static void WriteLineIf(bool condition, string message)
780 {
781 if (condition)
782 {
783 WriteLine(message);
784 }
785 }
786
787 public static void WriteLineIf(bool condition, object value)
788 {
789 if (condition)
790 {
792 }
793 }
794
795 public static void WriteLineIf(bool condition, string message, string category)
796 {
797 if (condition)
798 {
799 WriteLine(message, category);
800 }
801 }
802
803 public static void WriteLineIf(bool condition, object value, string category)
804 {
805 if (condition)
806 {
807 WriteLine(value, category);
808 }
809 }
810}
static int IndentSize
Definition Debug.cs:202
static int IndentLevel
Definition Debug.cs:189
static DebugProvider SetProvider(DebugProvider provider)
Definition Debug.cs:214
override void OnIndentLevelChanged(int indentLevel)
override void Fail(string message, string detailMessage)
override void WriteLine(string message)
override void OnIndentSizeChanged(int indentSize)
static volatile bool s_useGlobalLock
static void Write(object value)
static void Fail(string message)
static void Assert(bool condition, string message)
static void WriteLineIf(bool condition, string message, string category)
static void WriteLine(object value, string category)
static void WriteIf(bool condition, object value, string category)
static void WriteIf(bool condition, string message, string category)
static void Fail(string message, string detailMessage)
static void WriteLine(string message)
static void WriteIf(bool condition, object value)
static void Write(object value, string category)
static void WriteIf(bool condition, string message)
static readonly object critSec
static void WriteLineIf(bool condition, string message)
static void WriteLine(object value)
static TraceListenerCollection Listeners
static void WriteLineIf(bool condition, object value)
static void Write(string message, string category)
static void Assert(bool condition, string message, string detailMessage)
static volatile TraceListenerCollection s_listeners
static void Assert(bool condition)
static void Write(string message)
static volatile string s_appName
static volatile bool s_autoFlush
static void WriteLineIf(bool condition, object value, string category)
static void WriteLine(string message, string category)
static void TraceEvent(TraceEventType eventType, int id, string format, params object[] args)
static volatile bool s_settingsInitialized
virtual void Fail(string? message)
void WriteLine(string? message)
void Write(string? message)
virtual void TraceEvent(TraceEventCache? eventCache, string source, TraceEventType eventType, int id)
static ? Assembly GetEntryAssembly()
Definition Assembly.cs:486