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.NetworkInformation")]
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 Error(object thisOrContextObject, object message, [CallerMemberName] string memberName = null)
22 {
23 if (Log.IsEnabled())
24 {
25 Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(message).ToString());
26 }
27 }
28
29 [Event(5, Level = EventLevel.Error, Keywords = (EventKeywords)1L)]
30 private void ErrorMessage(string thisOrContextObject, string memberName, string message)
31 {
32 WriteEvent(5, thisOrContextObject, memberName ?? "(?)", message);
33 }
34
35 [NonEvent]
36 public static string IdOf(object value)
37 {
38 if (value == null)
39 {
40 return "(null)";
41 }
42 return value.GetType().Name + "#" + GetHashCode(value);
43 }
44
45 [NonEvent]
46 public static int GetHashCode(object value)
47 {
48 return value?.GetHashCode() ?? 0;
49 }
50
51 [NonEvent]
52 public static object Format(object value)
53 {
54 if (value == null)
55 {
56 return "(null)";
57 }
58 string text = null;
59 if (text != null)
60 {
61 return text;
62 }
63 if (value is Array array)
64 {
65 return $"{array.GetType().GetElementType()}[{((Array)value).Length}]";
66 }
68 {
69 return $"{collection.GetType().Name}({collection.Count})";
70 }
71 if (value is SafeHandle safeHandle)
72 {
73 return $"{safeHandle.GetType().Name}:{safeHandle.GetHashCode()}(0x{safeHandle.DangerousGetHandle():X})";
74 }
75 if (value is IntPtr)
76 {
77 return $"0x{value:X}";
78 }
79 string text2 = value.ToString();
80 if (text2 == null || text2 == value.GetType().FullName)
81 {
82 return IdOf(value);
83 }
84 return value;
85 }
86}
static readonly System.Net.NetEventSource Log
void ErrorMessage(string thisOrContextObject, string memberName, string message)
static void Error(object thisOrContextObject, object message, [CallerMemberName] string memberName=null)
static string IdOf(object value)
static int GetHashCode(object value)
unsafe void WriteEvent(int eventId, int arg1, int arg2, int arg3, string arg4, string arg5)
static object Format(object value)