Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NetEventSource.cs
Go to the documentation of this file.
5
6namespace System.Net;
7
8[EventSource(Name = "Private.InternalDiagnostics.System.Net.Quic")]
9internal sealed class NetEventSource : EventSource
10{
11 public static class Keywords
12 {
13 public const EventKeywords Default = (EventKeywords)1L;
14
15 public const EventKeywords Debug = (EventKeywords)2L;
16 }
17
18 public static readonly System.Net.NetEventSource Log = new System.Net.NetEventSource();
19
20 [NonEvent]
21 public static void Info(object thisOrContextObject, FormattableString formattableString = null, [CallerMemberName] string memberName = null)
22 {
23 if (Log.IsEnabled())
24 {
25 Log.Info(IdOf(thisOrContextObject), memberName, (formattableString != null) ? Format(formattableString) : "");
26 }
27 }
28
29 [NonEvent]
30 public static void Info(object thisOrContextObject, object message, [CallerMemberName] string memberName = null)
31 {
32 if (Log.IsEnabled())
33 {
34 Log.Info(IdOf(thisOrContextObject), memberName, Format(message).ToString());
35 }
36 }
37
38 [Event(4, Level = EventLevel.Informational, Keywords = (EventKeywords)1L)]
39 private void Info(string thisOrContextObject, string memberName, string message)
40 {
41 WriteEvent(4, thisOrContextObject, memberName ?? "(?)", message);
42 }
43
44 [NonEvent]
45 public static void Error(object thisOrContextObject, FormattableString formattableString, [CallerMemberName] string memberName = null)
46 {
47 if (Log.IsEnabled())
48 {
49 Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(formattableString));
50 }
51 }
52
53 [Event(5, Level = EventLevel.Error, Keywords = (EventKeywords)1L)]
54 private void ErrorMessage(string thisOrContextObject, string memberName, string message)
55 {
56 WriteEvent(5, thisOrContextObject, memberName ?? "(?)", message);
57 }
58
59 [NonEvent]
60 public static string IdOf(object value)
61 {
62 if (value == null)
63 {
64 return "(null)";
65 }
66 return value.GetType().Name + "#" + GetHashCode(value);
67 }
68
69 [NonEvent]
70 public static int GetHashCode(object value)
71 {
72 return value?.GetHashCode() ?? 0;
73 }
74
75 [NonEvent]
76 public static object Format(object value)
77 {
78 if (value == null)
79 {
80 return "(null)";
81 }
82 string text = null;
83 if (text != null)
84 {
85 return text;
86 }
87 if (value is Array array)
88 {
89 return $"{array.GetType().GetElementType()}[{((Array)value).Length}]";
90 }
92 {
93 return $"{collection.GetType().Name}({collection.Count})";
94 }
95 if (value is SafeHandle safeHandle)
96 {
97 return $"{safeHandle.GetType().Name}:{safeHandle.GetHashCode()}(0x{safeHandle.DangerousGetHandle():X})";
98 }
99 if (value is IntPtr)
100 {
101 return $"0x{value:X}";
102 }
103 string text2 = value.ToString();
104 if (text2 == null || text2 == value.GetType().FullName)
105 {
106 return IdOf(value);
107 }
108 return value;
109 }
110
111 [NonEvent]
112 private static string Format(FormattableString s)
113 {
114 switch (s.ArgumentCount)
115 {
116 case 0:
117 return s.Format;
118 case 1:
119 return string.Format(s.Format, Format(s.GetArgument(0)));
120 case 2:
121 return string.Format(s.Format, Format(s.GetArgument(0)), Format(s.GetArgument(1)));
122 case 3:
123 return string.Format(s.Format, Format(s.GetArgument(0)), Format(s.GetArgument(1)), Format(s.GetArgument(2)));
124 default:
125 {
126 object[] arguments = s.GetArguments();
127 object[] array = new object[arguments.Length];
128 for (int i = 0; i < arguments.Length; i++)
129 {
130 array[i] = Format(arguments[i]);
131 }
132 return string.Format(s.Format, array);
133 }
134 }
135 }
136}
static readonly System.Net.NetEventSource Log
void ErrorMessage(string thisOrContextObject, string memberName, string message)
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
void Info(string thisOrContextObject, string memberName, string message)
static string IdOf(object value)
static string Format(FormattableString s)
static void Error(object thisOrContextObject, FormattableString formattableString, [CallerMemberName] string memberName=null)
static int GetHashCode(object value)
unsafe void WriteEvent(int eventId, int arg1, int arg2, int arg3, string arg4, string arg5)
static void Info(object thisOrContextObject, object message, [CallerMemberName] string memberName=null)
static object Format(object value)