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.Primitives")]
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 NetEventSource Log = new 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 string IdOf(object value)
46 {
47 if (value == null)
48 {
49 return "(null)";
50 }
51 return value.GetType().Name + "#" + GetHashCode(value);
52 }
53
54 [NonEvent]
55 public static int GetHashCode(object value)
56 {
57 return value?.GetHashCode() ?? 0;
58 }
59
60 [NonEvent]
61 public static object Format(object value)
62 {
63 if (value == null)
64 {
65 return "(null)";
66 }
67 string text = null;
68 if (text != null)
69 {
70 return text;
71 }
72 if (value is Array array)
73 {
74 return $"{array.GetType().GetElementType()}[{((Array)value).Length}]";
75 }
77 {
78 return $"{collection.GetType().Name}({collection.Count})";
79 }
80 if (value is SafeHandle safeHandle)
81 {
82 return $"{safeHandle.GetType().Name}:{safeHandle.GetHashCode()}(0x{safeHandle.DangerousGetHandle():X})";
83 }
84 if (value is IntPtr)
85 {
86 return $"0x{value:X}";
87 }
88 string text2 = value.ToString();
89 if (text2 == null || text2 == value.GetType().FullName)
90 {
91 return IdOf(value);
92 }
93 return value;
94 }
95
96 [NonEvent]
97 private static string Format(FormattableString s)
98 {
99 switch (s.ArgumentCount)
100 {
101 case 0:
102 return s.Format;
103 case 1:
104 return string.Format(s.Format, Format(s.GetArgument(0)));
105 case 2:
106 return string.Format(s.Format, Format(s.GetArgument(0)), Format(s.GetArgument(1)));
107 case 3:
108 return string.Format(s.Format, Format(s.GetArgument(0)), Format(s.GetArgument(1)), Format(s.GetArgument(2)));
109 default:
110 {
111 object[] arguments = s.GetArguments();
112 object[] array = new object[arguments.Length];
113 for (int i = 0; i < arguments.Length; i++)
114 {
115 array[i] = Format(arguments[i]);
116 }
117 return string.Format(s.Format, array);
118 }
119 }
120 }
121}
static readonly System.Net.NetEventSource Log
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 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)