Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
EventSource.cs
Go to the documentation of this file.
9using System.Text;
12
14
16[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate because the nested type OverrideEventProvider's base type EventProvider defines a delegate. This includes Delegate and MulticastDelegate methods which require unreferenced code, but EnsureDescriptorsInitialized does not access these members and is safe to call.")]
17[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2115:ReflectionToDynamicallyAccessedMembers", Justification = "EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate because the nested type OverrideEventProvider's base type EventProvider defines a delegate. This includes Delegate and MulticastDelegate methods which have dynamically accessed members requirements, but EnsureDescriptorsInitialized does not access these members and is safe to call.")]
19{
20 protected internal struct EventData
21 {
22 internal ulong m_Ptr;
23
24 internal int m_Size;
25
26 internal int m_Reserved;
27
28 public unsafe IntPtr DataPointer
29 {
30 get
31 {
32 return (IntPtr)(void*)m_Ptr;
33 }
34 set
35 {
36 m_Ptr = (ulong)(void*)value;
37 }
38 }
39
40 public int Size
41 {
42 get
43 {
44 return m_Size;
45 }
46 set
47 {
48 m_Size = value;
49 }
50 }
51
52 internal int Reserved
53 {
54 get
55 {
56 return m_Reserved;
57 }
58 set
59 {
61 }
62 }
63
64 internal unsafe void SetMetadata(byte* pointer, int size, int reserved)
65 {
66 m_Ptr = (ulong)pointer;
67 m_Size = size;
68 m_Reserved = reserved;
69 }
70 }
71
72 private sealed class OverrideEventProvider : EventProvider
73 {
74 private readonly EventSource m_eventSource;
75
77
84
85 protected override void OnControllerCommand(ControllerCommand command, IDictionary<string, string> arguments, int perEventSourceSessionId, int etwSessionId)
86 {
87 EventListener listener = null;
88 m_eventSource.SendCommand(listener, m_eventProviderType, perEventSourceSessionId, etwSessionId, (EventCommand)command, IsEnabled(), base.Level, base.MatchAnyKeyword, arguments);
89 }
90 }
91
92 internal struct EventMetadata
93 {
95
97
99
101
102 public bool EnabledForETW;
103
105
107
108 public string Name;
109
110 public string Message;
111
113
115
117
119
121
123
125
127
129 {
130 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
131 [RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")]
132 get
133 {
134 if (_traceLoggingEventTypes == null)
135 {
138 }
140 }
141 }
142
144 {
145 get
146 {
147 if (_parameterNames == null)
148 {
149 ParameterInfo[] parameters = Parameters;
150 string[] array = new string[parameters.Length];
151 for (int i = 0; i < array.Length; i++)
152 {
153 array[i] = parameters[i].Name;
154 }
156 }
157 return _parameterNames;
158 }
159 }
160
162 {
163 get
164 {
165 return _parameterTypes ?? (_parameterTypes = GetParameterTypes(Parameters));
166 static Type[] GetParameterTypes(ParameterInfo[] parameters)
167 {
168 Type[] array = new Type[parameters.Length];
169 for (int i = 0; i < array.Length; i++)
170 {
171 array[i] = parameters[i].ParameterType;
172 }
173 return array;
174 }
175 }
176 }
177 }
178
180
181 private string m_name;
182
183 internal int m_id;
184
185 private Guid m_guid;
186
187 internal volatile EventMetadata[] m_eventData;
188
189 private volatile byte[] m_rawManifest;
190
192
194
196
198
200
202
204
206
207 private object m_createEventLock;
208
210
212
213 private bool m_completelyInited;
214
216
218
220
221 private string[] m_traits;
222
225
226 internal volatile ulong[] m_channelData;
227
229
230 internal const string s_ActivityStartSuffix = "Start";
231
232 internal const string s_ActivityStopSuffix = "Stop";
233
234 internal const string DuplicateSourceNamesSwitch = "System.Diagnostics.Tracing.EventSource.AllowDuplicateSourceNames";
235
236 private static readonly bool AllowDuplicateSourceNames = AppContext.TryGetSwitch("System.Diagnostics.Tracing.EventSource.AllowDuplicateSourceNames", out var isEnabled) && isEnabled;
237
238 private byte[] m_providerMetadata;
239
240 private const string EventSourceRequiresUnreferenceMessage = "EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type";
241
242 private const string EventSourceSuppressMessage = "Parameters to this method are primitive and are trimmer safe";
243
245
246 internal static bool IsSupported { get; } = InitializeIsSupported();
247
248
249 public string Name => m_name;
250
251 public Guid Guid => m_guid;
252
254
256
258 {
259 get
260 {
261 if (!IsSupported)
262 {
263 return default(Guid);
264 }
265 Guid ActivityId = default(Guid);
266 Interop.Advapi32.EventActivityIdControl(Interop.Advapi32.ActivityControl.EVENT_ACTIVITY_CTRL_GET_ID, ref ActivityId);
267 return ActivityId;
268 }
269 }
270
272
273 private bool ThrowOnEventWriteErrors => (m_config & EventSourceSettings.ThrowOnEventWriteErrors) != 0;
274
275 private bool SelfDescribingEvents => (m_config & EventSourceSettings.EtwSelfDescribingEventFormat) != 0;
276
278
297
298 private static bool InitializeIsSupported()
299 {
300 if (!AppContext.TryGetSwitch("System.Diagnostics.Tracing.EventSource.IsSupported", out var isEnabled))
301 {
302 return true;
303 }
304 return isEnabled;
305 }
306
307 public bool IsEnabled()
308 {
310 }
311
312 public bool IsEnabled(EventLevel level, EventKeywords keywords)
313 {
314 return IsEnabled(level, keywords, EventChannel.None);
315 }
316
317 public bool IsEnabled(EventLevel level, EventKeywords keywords, EventChannel channel)
318 {
319 if (!IsEnabled())
320 {
321 return false;
322 }
323 if (!IsEnabledCommon(m_eventSourceEnabled, m_level, m_matchAnyKeyword, level, keywords, channel))
324 {
325 return false;
326 }
327 return true;
328 }
329
331 {
332 if (eventSourceType == null)
333 {
334 throw new ArgumentNullException("eventSourceType");
335 }
337 string name = eventSourceType.Name;
338 if (eventSourceAttribute != null)
339 {
340 if (eventSourceAttribute.Guid != null && Guid.TryParse(eventSourceAttribute.Guid, out var result))
341 {
342 return result;
343 }
344 if (eventSourceAttribute.Name != null)
345 {
346 name = eventSourceAttribute.Name;
347 }
348 }
349 if (name == null)
350 {
351 throw new ArgumentException(SR.Argument_InvalidTypeName, "eventSourceType");
352 }
353 return GenerateGuidFromName(name.ToUpperInvariant());
354 }
355
356 public static string GetName(Type eventSourceType)
357 {
359 }
360
361 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:ReflectionToDynamicallyAccessedMembers", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which has dynamically accessed members requirements, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
366
367 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:ReflectionToDynamicallyAccessedMembers", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which has dynamically accessed members requirements, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
369 {
370 if (!IsSupported)
371 {
372 return null;
373 }
374 if (eventSourceType == null)
375 {
376 throw new ArgumentNullException("eventSourceType");
377 }
379 if (array != null)
380 {
381 return Encoding.UTF8.GetString(array, 0, array.Length);
382 }
383 return null;
384 }
385
387 {
388 if (!IsSupported)
389 {
390 return Array.Empty<EventSource>();
391 }
394 {
396 {
397 if (s_EventSource.TryGetTarget(out var target) && !target.IsDisposed)
398 {
399 list.Add(target);
400 }
401 }
402 return list;
403 }
404 }
405
407 {
408 if (IsSupported)
409 {
410 if (eventSource == null)
411 {
412 throw new ArgumentNullException("eventSource");
413 }
414 if (command <= EventCommand.Update && command != EventCommand.SendManifest)
415 {
416 throw new ArgumentException(SR.EventSource_InvalidCommand, "command");
417 }
418 eventSource.SendCommand(null, EventProviderType.ETW, 0, 0, command, enable: true, EventLevel.LogAlways, EventKeywords.None, commandArguments);
419 }
420 }
421
422 public string? GetTrait(string key)
423 {
424 if (m_traits != null)
425 {
426 for (int i = 0; i < m_traits.Length - 1; i += 2)
427 {
428 if (m_traits[i] == key)
429 {
430 return m_traits[i + 1];
431 }
432 }
433 }
434 return null;
435 }
436
437 public override string ToString()
438 {
439 if (!IsSupported)
440 {
441 return base.ToString();
442 }
444 }
445
447 {
448 if (IsSupported)
449 {
450 if (TplEventSource.Log != null)
451 {
452 TplEventSource.Log.SetActivityId(activityId);
453 }
456 }
457 }
458
474
479
484
486 : this(settings, (string[]?)null)
487 {
488 }
489
490 protected EventSource(EventSourceSettings settings, params string[]? traits)
491 {
492 if (IsSupported)
493 {
495 m_config = ValidateSettings(settings);
496 Type type = GetType();
497 Guid guid = GetGuid(type);
498 string name = GetName(type);
499 Initialize(guid, name, traits);
500 }
501 }
502
503 private unsafe void DefineEventPipeEvents()
504 {
506 {
507 return;
508 }
509 int num = m_eventData.Length;
510 for (int i = 0; i < num; i++)
511 {
512 uint eventId = (uint)m_eventData[i].Descriptor.EventId;
513 if (eventId != 0)
514 {
515 byte[] array = EventPipeMetadataGenerator.Instance.GenerateEventMetadata(m_eventData[i]);
516 uint metadataLength = ((array != null) ? ((uint)array.Length) : 0u);
517 string name = m_eventData[i].Name;
518 long keywords = m_eventData[i].Descriptor.Keywords;
519 uint version = m_eventData[i].Descriptor.Version;
520 uint level = m_eventData[i].Descriptor.Level;
521 fixed (byte* pMetadata = array)
522 {
523 IntPtr eventHandle = m_eventPipeProvider.m_eventProvider.DefineEventHandle(eventId, name, keywords, version, level, pMetadata, metadataLength);
524 m_eventData[i].EventHandle = eventHandle;
525 }
526 }
527 }
528 }
529
531 {
532 }
533
534 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
535 protected unsafe void WriteEvent(int eventId)
536 {
537 WriteEventCore(eventId, 0, null);
538 }
539
540 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
541 protected unsafe void WriteEvent(int eventId, int arg1)
542 {
543 if (IsEnabled())
544 {
546 ptr->DataPointer = (IntPtr)(&arg1);
547 ptr->Size = 4;
548 ptr->Reserved = 0;
550 }
551 }
552
553 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
554 protected unsafe void WriteEvent(int eventId, int arg1, int arg2)
555 {
556 if (IsEnabled())
557 {
559 ptr->DataPointer = (IntPtr)(&arg1);
560 ptr->Size = 4;
561 ptr->Reserved = 0;
562 ptr[1].DataPointer = (IntPtr)(&arg2);
563 ptr[1].Size = 4;
564 ptr[1].Reserved = 0;
566 }
567 }
568
569 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
570 protected unsafe void WriteEvent(int eventId, int arg1, int arg2, int arg3)
571 {
572 if (IsEnabled())
573 {
575 ptr->DataPointer = (IntPtr)(&arg1);
576 ptr->Size = 4;
577 ptr->Reserved = 0;
578 ptr[1].DataPointer = (IntPtr)(&arg2);
579 ptr[1].Size = 4;
580 ptr[1].Reserved = 0;
581 ptr[2].DataPointer = (IntPtr)(&arg3);
582 ptr[2].Size = 4;
583 ptr[2].Reserved = 0;
585 }
586 }
587
588 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
589 protected unsafe void WriteEvent(int eventId, long arg1)
590 {
591 if (IsEnabled())
592 {
594 ptr->DataPointer = (IntPtr)(&arg1);
595 ptr->Size = 8;
596 ptr->Reserved = 0;
598 }
599 }
600
601 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
602 protected unsafe void WriteEvent(int eventId, long arg1, long arg2)
603 {
604 if (IsEnabled())
605 {
607 ptr->DataPointer = (IntPtr)(&arg1);
608 ptr->Size = 8;
609 ptr->Reserved = 0;
610 ptr[1].DataPointer = (IntPtr)(&arg2);
611 ptr[1].Size = 8;
612 ptr[1].Reserved = 0;
614 }
615 }
616
617 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
618 protected unsafe void WriteEvent(int eventId, long arg1, long arg2, long arg3)
619 {
620 if (IsEnabled())
621 {
623 ptr->DataPointer = (IntPtr)(&arg1);
624 ptr->Size = 8;
625 ptr->Reserved = 0;
626 ptr[1].DataPointer = (IntPtr)(&arg2);
627 ptr[1].Size = 8;
628 ptr[1].Reserved = 0;
629 ptr[2].DataPointer = (IntPtr)(&arg3);
630 ptr[2].Size = 8;
631 ptr[2].Reserved = 0;
633 }
634 }
635
636 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
637 protected unsafe void WriteEvent(int eventId, string? arg1)
638 {
639 if (IsEnabled())
640 {
641 if (arg1 == null)
642 {
643 arg1 = "";
644 }
645 fixed (char* ptr2 = arg1)
646 {
648 ptr->DataPointer = (IntPtr)ptr2;
649 ptr->Size = (arg1.Length + 1) * 2;
650 ptr->Reserved = 0;
652 }
653 }
654 }
655
656 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
657 protected unsafe void WriteEvent(int eventId, string? arg1, string? arg2)
658 {
659 //The blocks IL_0040 are reachable both inside and outside the pinned region starting at IL_003d. ILSpy has duplicated these blocks in order to place them both within and outside the `fixed` statement.
660 if (!IsEnabled())
661 {
662 return;
663 }
664 if (arg1 == null)
665 {
666 arg1 = "";
667 }
668 if (arg2 == null)
669 {
670 arg2 = "";
671 }
672 fixed (char* ptr3 = arg1)
673 {
674 char* intPtr;
675 if (arg2 == null)
676 {
677 char* ptr;
678 intPtr = (ptr = null);
680 ptr2->DataPointer = (IntPtr)ptr3;
681 ptr2->Size = (arg1.Length + 1) * 2;
682 ptr2->Reserved = 0;
683 ptr2[1].DataPointer = (IntPtr)ptr;
684 ptr2[1].Size = (arg2.Length + 1) * 2;
685 ptr2[1].Reserved = 0;
687 return;
688 }
689 fixed (char* ptr4 = &arg2.GetPinnableReference())
690 {
691 char* ptr;
692 intPtr = (ptr = ptr4);
694 ptr2->DataPointer = (IntPtr)ptr3;
695 ptr2->Size = (arg1.Length + 1) * 2;
696 ptr2->Reserved = 0;
697 ptr2[1].DataPointer = (IntPtr)ptr;
698 ptr2[1].Size = (arg2.Length + 1) * 2;
699 ptr2[1].Reserved = 0;
701 }
702 }
703 }
704
705 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
706 protected unsafe void WriteEvent(int eventId, string? arg1, string? arg2, string? arg3)
707 {
708 //The blocks IL_004b, IL_004e, IL_0060, IL_0122 are reachable both inside and outside the pinned region starting at IL_0048. ILSpy has duplicated these blocks in order to place them both within and outside the `fixed` statement.
709 if (!IsEnabled())
710 {
711 return;
712 }
713 if (arg1 == null)
714 {
715 arg1 = "";
716 }
717 if (arg2 == null)
718 {
719 arg2 = "";
720 }
721 if (arg3 == null)
722 {
723 arg3 = "";
724 }
725 fixed (char* ptr5 = arg1)
726 {
727 char* intPtr;
728 if (arg2 == null)
729 {
730 char* ptr;
731 intPtr = (ptr = null);
732 fixed (char* ptr2 = arg3)
733 {
734 char* ptr3 = ptr2;
736 ptr4->DataPointer = (IntPtr)ptr5;
737 ptr4->Size = (arg1.Length + 1) * 2;
738 ptr4->Reserved = 0;
739 ptr4[1].DataPointer = (IntPtr)ptr;
740 ptr4[1].Size = (arg2.Length + 1) * 2;
741 ptr4[1].Reserved = 0;
742 ptr4[2].DataPointer = (IntPtr)ptr3;
743 ptr4[2].Size = (arg3.Length + 1) * 2;
744 ptr4[2].Reserved = 0;
746 }
747 return;
748 }
749 fixed (char* ptr6 = &arg2.GetPinnableReference())
750 {
751 char* ptr;
752 intPtr = (ptr = ptr6);
753 fixed (char* ptr2 = arg3)
754 {
755 char* ptr3 = ptr2;
757 ptr4->DataPointer = (IntPtr)ptr5;
758 ptr4->Size = (arg1.Length + 1) * 2;
759 ptr4->Reserved = 0;
760 ptr4[1].DataPointer = (IntPtr)ptr;
761 ptr4[1].Size = (arg2.Length + 1) * 2;
762 ptr4[1].Reserved = 0;
763 ptr4[2].DataPointer = (IntPtr)ptr3;
764 ptr4[2].Size = (arg3.Length + 1) * 2;
765 ptr4[2].Reserved = 0;
767 }
768 }
769 }
770 }
771
772 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
773 protected unsafe void WriteEvent(int eventId, string? arg1, int arg2)
774 {
775 if (IsEnabled())
776 {
777 if (arg1 == null)
778 {
779 arg1 = "";
780 }
781 fixed (char* ptr2 = arg1)
782 {
784 ptr->DataPointer = (IntPtr)ptr2;
785 ptr->Size = (arg1.Length + 1) * 2;
786 ptr->Reserved = 0;
787 ptr[1].DataPointer = (IntPtr)(&arg2);
788 ptr[1].Size = 4;
789 ptr[1].Reserved = 0;
791 }
792 }
793 }
794
795 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
796 protected unsafe void WriteEvent(int eventId, string? arg1, int arg2, int arg3)
797 {
798 if (IsEnabled())
799 {
800 if (arg1 == null)
801 {
802 arg1 = "";
803 }
804 fixed (char* ptr2 = arg1)
805 {
807 ptr->DataPointer = (IntPtr)ptr2;
808 ptr->Size = (arg1.Length + 1) * 2;
809 ptr->Reserved = 0;
810 ptr[1].DataPointer = (IntPtr)(&arg2);
811 ptr[1].Size = 4;
812 ptr[1].Reserved = 0;
813 ptr[2].DataPointer = (IntPtr)(&arg3);
814 ptr[2].Size = 4;
815 ptr[2].Reserved = 0;
817 }
818 }
819 }
820
821 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
822 protected unsafe void WriteEvent(int eventId, string? arg1, long arg2)
823 {
824 if (IsEnabled())
825 {
826 if (arg1 == null)
827 {
828 arg1 = "";
829 }
830 fixed (char* ptr2 = arg1)
831 {
833 ptr->DataPointer = (IntPtr)ptr2;
834 ptr->Size = (arg1.Length + 1) * 2;
835 ptr->Reserved = 0;
836 ptr[1].DataPointer = (IntPtr)(&arg2);
837 ptr[1].Size = 8;
838 ptr[1].Reserved = 0;
840 }
841 }
842 }
843
844 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
845 protected unsafe void WriteEvent(int eventId, long arg1, string? arg2)
846 {
847 if (IsEnabled())
848 {
849 if (arg2 == null)
850 {
851 arg2 = "";
852 }
853 fixed (char* ptr2 = arg2)
854 {
856 ptr->DataPointer = (IntPtr)(&arg1);
857 ptr->Size = 8;
858 ptr->Reserved = 0;
859 ptr[1].DataPointer = (IntPtr)ptr2;
860 ptr[1].Size = (arg2.Length + 1) * 2;
861 ptr[1].Reserved = 0;
863 }
864 }
865 }
866
867 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
868 protected unsafe void WriteEvent(int eventId, int arg1, string? arg2)
869 {
870 if (IsEnabled())
871 {
872 if (arg2 == null)
873 {
874 arg2 = "";
875 }
876 fixed (char* ptr2 = arg2)
877 {
879 ptr->DataPointer = (IntPtr)(&arg1);
880 ptr->Size = 4;
881 ptr->Reserved = 0;
882 ptr[1].DataPointer = (IntPtr)ptr2;
883 ptr[1].Size = (arg2.Length + 1) * 2;
884 ptr[1].Reserved = 0;
886 }
887 }
888 }
889
890 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
891 protected unsafe void WriteEvent(int eventId, byte[]? arg1)
892 {
893 if (!IsEnabled())
894 {
895 return;
896 }
898 if (arg1 == null || arg1.Length == 0)
899 {
900 int num = 0;
901 ptr->DataPointer = (IntPtr)(&num);
902 ptr->Size = 4;
903 ptr->Reserved = 0;
904 ptr[1].DataPointer = (IntPtr)(&num);
905 ptr[1].Size = 0;
906 ptr[1].Reserved = 0;
908 return;
909 }
910 int size = arg1.Length;
911 fixed (byte* ptr2 = &arg1[0])
912 {
913 ptr->DataPointer = (IntPtr)(&size);
914 ptr->Size = 4;
915 ptr->Reserved = 0;
916 ptr[1].DataPointer = (IntPtr)ptr2;
917 ptr[1].Size = size;
918 ptr[1].Reserved = 0;
920 }
921 }
922
923 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
924 protected unsafe void WriteEvent(int eventId, long arg1, byte[]? arg2)
925 {
926 if (!IsEnabled())
927 {
928 return;
929 }
931 ptr->DataPointer = (IntPtr)(&arg1);
932 ptr->Size = 8;
933 ptr->Reserved = 0;
934 if (arg2 == null || arg2.Length == 0)
935 {
936 int num = 0;
937 ptr[1].DataPointer = (IntPtr)(&num);
938 ptr[1].Size = 4;
939 ptr[1].Reserved = 0;
940 ptr[2].DataPointer = (IntPtr)(&num);
941 ptr[2].Size = 0;
942 ptr[2].Reserved = 0;
944 return;
945 }
946 int size = arg2.Length;
947 fixed (byte* ptr2 = &arg2[0])
948 {
949 ptr[1].DataPointer = (IntPtr)(&size);
950 ptr[1].Size = 4;
951 ptr[1].Reserved = 0;
952 ptr[2].DataPointer = (IntPtr)ptr2;
953 ptr[2].Size = size;
954 ptr[2].Reserved = 0;
956 }
957 }
958
959 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
960 [RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")]
961 [CLSCompliant(false)]
962 protected unsafe void WriteEventCore(int eventId, int eventDataCount, EventData* data)
963 {
965 }
966
967 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
968 [RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")]
969 [CLSCompliant(false)]
971 {
972 if (!IsEnabled())
973 {
974 return;
975 }
976 try
977 {
979 EventOpcode opcode = (EventOpcode)reference.Descriptor.Opcode;
980 Guid* ptr = null;
983 if (opcode != 0 && relatedActivityId == null && (reference.ActivityOptions & EventActivityOptions.Disable) == 0)
984 {
985 switch (opcode)
986 {
987 case EventOpcode.Start:
989 break;
990 case EventOpcode.Stop:
992 break;
993 }
994 if (activityId != Guid.Empty)
995 {
996 ptr = &activityId;
997 }
999 {
1001 }
1002 }
1004 {
1005 if (reference.EnabledForETW && !m_etwProvider.WriteEvent(ref reference.Descriptor, reference.EventHandle, ptr, relatedActivityId, eventDataCount, (IntPtr)data))
1006 {
1008 }
1009 if (reference.EnabledForEventPipe && !m_eventPipeProvider.WriteEvent(ref reference.Descriptor, reference.EventHandle, ptr, relatedActivityId, eventDataCount, (IntPtr)data))
1010 {
1012 }
1013 }
1014 else if (reference.EnabledForETW || reference.EnabledForEventPipe)
1015 {
1017 eventSourceOptions.Keywords = (EventKeywords)reference.Descriptor.Keywords;
1018 eventSourceOptions.Level = (EventLevel)reference.Descriptor.Level;
1019 eventSourceOptions.Opcode = (EventOpcode)reference.Descriptor.Opcode;
1021 WriteMultiMerge(reference.Name, ref options, reference.TraceLoggingEventTypes, ptr, relatedActivityId, data);
1022 }
1023 if (m_Dispatchers != null && reference.EnabledForAnyListener)
1024 {
1027 }
1028 }
1029 catch (Exception ex)
1030 {
1032 {
1033 throw;
1034 }
1036 }
1037 }
1038
1039 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
1040 [RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")]
1041 protected unsafe void WriteEvent(int eventId, params object?[] args)
1042 {
1044 }
1045
1046 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
1047 [RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")]
1052
1053 public void Dispose()
1054 {
1055 Dispose(disposing: true);
1056 GC.SuppressFinalize(this);
1057 }
1058
1059 protected virtual void Dispose(bool disposing)
1060 {
1061 if (!IsSupported)
1062 {
1063 return;
1064 }
1065 if (disposing)
1066 {
1068 {
1069 try
1070 {
1072 }
1073 catch
1074 {
1075 }
1076 m_eventSourceEnabled = false;
1077 }
1078 if (m_etwProvider != null)
1079 {
1080 m_etwProvider.Dispose();
1081 m_etwProvider = null;
1082 }
1083 if (m_eventPipeProvider != null)
1084 {
1085 m_eventPipeProvider.Dispose();
1086 m_eventPipeProvider = null;
1087 }
1088 }
1089 m_eventSourceEnabled = false;
1090 m_eventSourceDisposed = true;
1091 }
1092
1094 {
1095 Dispose(disposing: false);
1096 }
1097
1098 private unsafe void WriteEventRaw(string eventName, ref EventDescriptor eventDescriptor, IntPtr eventHandle, Guid* activityID, Guid* relatedActivityID, int dataCount, IntPtr data)
1099 {
1100 bool flag = true;
1101 flag &= m_etwProvider == null;
1102 if (m_etwProvider != null && !m_etwProvider.WriteEventRaw(ref eventDescriptor, eventHandle, activityID, relatedActivityID, dataCount, data))
1103 {
1104 ThrowEventSourceException(eventName);
1105 }
1106 flag &= m_eventPipeProvider == null;
1107 if (m_eventPipeProvider != null && !m_eventPipeProvider.WriteEventRaw(ref eventDescriptor, eventHandle, activityID, relatedActivityID, dataCount, data))
1108 {
1109 ThrowEventSourceException(eventName);
1110 }
1111 if (flag)
1112 {
1113 ThrowEventSourceException(eventName);
1114 }
1115 }
1116
1121
1122 internal EventSource(Guid eventSourceGuid, string eventSourceName, EventSourceSettings settings, string[] traits = null)
1123 {
1124 if (IsSupported)
1125 {
1127 m_config = ValidateSettings(settings);
1129 }
1130 }
1131
1132 private unsafe void Initialize(Guid eventSourceGuid, string eventSourceName, string[] traits)
1133 {
1134 try
1135 {
1136 m_traits = traits;
1137 if (m_traits != null && m_traits.Length % 2 != 0)
1138 {
1139 throw new ArgumentException(SR.EventSource_TraitEven, "traits");
1140 }
1141 if (eventSourceGuid == Guid.Empty)
1142 {
1144 }
1145 if (eventSourceName == null)
1146 {
1148 }
1152 if (ProviderMetadata.Length == 0)
1153 {
1155 }
1157 overrideEventProvider.Register(this);
1160 {
1161 overrideEventProvider2.Register(this);
1162 }
1165 if (Name != "System.Diagnostics.Eventing.FrameworkEventSource" || Environment.IsWindows8OrAbove)
1166 {
1168 fixed (byte* data = providerMetadata)
1169 {
1170 m_etwProvider.SetInformation(Interop.Advapi32.EVENT_INFO_CLASS.SetTraits, data, (uint)providerMetadata.Length);
1171 }
1172 }
1174 m_completelyInited = true;
1175 }
1176 catch (Exception ex)
1177 {
1178 if (m_constructionException == null)
1179 {
1181 }
1182 ReportOutOfBandMessage("ERROR: Exception during construction of EventSource " + Name + ": " + ex.Message);
1183 }
1185 {
1187 {
1189 }
1190 }
1191 }
1192
1193 private static string GetName(Type eventSourceType, EventManifestOptions flags)
1194 {
1195 if (eventSourceType == null)
1196 {
1197 throw new ArgumentNullException("eventSourceType");
1198 }
1200 if (eventSourceAttribute != null && eventSourceAttribute.Name != null)
1201 {
1202 return eventSourceAttribute.Name;
1203 }
1204 return eventSourceType.Name;
1205 }
1206
1207 private static Guid GenerateGuidFromName(string name)
1208 {
1209 ReadOnlySpan<byte> input = new byte[16]
1210 {
1211 72, 44, 45, 178, 195, 144, 71, 200, 135, 248,
1212 26, 21, 191, 193, 48, 251
1213 };
1214 byte[] array = Encoding.BigEndianUnicode.GetBytes(name);
1219 Array.Resize(ref array, 16);
1221 array[7] = (byte)((array[7] & 0xFu) | 0x50u);
1222 return new Guid(array);
1223 }
1224
1225 private unsafe static void DecodeObjects(object[] decodedObjects, Type[] parameterTypes, EventData* data)
1226 {
1227 object obj;
1228 for (int i = 0; i < decodedObjects.Length; decodedObjects[i] = obj, i++, data++)
1229 {
1232 if (!(type == typeof(string)))
1233 {
1234 if (type == typeof(int))
1235 {
1236 obj = *(int*)(void*)dataPointer;
1237 continue;
1238 }
1239 TypeCode typeCode = Type.GetTypeCode(type);
1240 int size = data->Size;
1241 if (size == 4)
1242 {
1243 if ((uint)(typeCode - 5) <= 4u)
1244 {
1245 obj = *(int*)(void*)dataPointer;
1246 continue;
1247 }
1248 if (typeCode == TypeCode.UInt32)
1249 {
1250 obj = *(uint*)(void*)dataPointer;
1251 continue;
1252 }
1253 if (typeCode == TypeCode.Single)
1254 {
1255 obj = *(float*)(void*)dataPointer;
1256 continue;
1257 }
1258 if (typeCode == TypeCode.Boolean)
1259 {
1260 obj = *(int*)(void*)dataPointer == 1;
1261 continue;
1262 }
1263 if (type == typeof(byte[]))
1264 {
1265 data++;
1266 goto IL_0256;
1267 }
1268 if (IntPtr.Size != 4)
1269 {
1270 goto IL_0244;
1271 }
1272 }
1273 if (size <= 2)
1274 {
1275 switch (typeCode)
1276 {
1277 case TypeCode.Byte:
1278 obj = *(byte*)(void*)dataPointer;
1279 continue;
1280 case TypeCode.SByte:
1281 obj = *(sbyte*)(void*)dataPointer;
1282 continue;
1283 case TypeCode.Int16:
1284 obj = *(short*)(void*)dataPointer;
1285 continue;
1286 case TypeCode.UInt16:
1287 obj = *(ushort*)(void*)dataPointer;
1288 continue;
1289 case TypeCode.Char:
1290 obj = *(char*)(void*)dataPointer;
1291 continue;
1292 }
1293 }
1294 else if (size == 8)
1295 {
1296 switch (typeCode)
1297 {
1298 case TypeCode.Int64:
1299 obj = *(long*)(void*)dataPointer;
1300 continue;
1301 case TypeCode.UInt64:
1302 obj = *(ulong*)(void*)dataPointer;
1303 continue;
1304 case TypeCode.Double:
1305 obj = *(double*)(void*)dataPointer;
1306 continue;
1307 case TypeCode.DateTime:
1308 obj = *(DateTime*)(void*)dataPointer;
1309 continue;
1310 }
1311 _ = IntPtr.Size;
1312 if (type == typeof(IntPtr))
1313 {
1314 obj = *(IntPtr*)(void*)dataPointer;
1315 continue;
1316 }
1317 }
1318 else
1319 {
1320 if (typeCode == TypeCode.Decimal)
1321 {
1322 obj = *(decimal*)(void*)dataPointer;
1323 continue;
1324 }
1325 if (type == typeof(Guid))
1326 {
1327 obj = *(Guid*)(void*)dataPointer;
1328 continue;
1329 }
1330 }
1331 goto IL_0244;
1332 }
1333 goto IL_028a;
1334 IL_0256:
1335 if (data->Size == 0)
1336 {
1337 obj = Array.Empty<byte>();
1338 continue;
1339 }
1340 byte[] array = new byte[data->Size];
1341 Marshal.Copy(data->DataPointer, array, 0, array.Length);
1342 obj = array;
1343 continue;
1344 IL_0244:
1345 if (!(type != typeof(byte*)))
1346 {
1347 goto IL_0256;
1348 }
1349 goto IL_028a;
1350 IL_028a:
1351 obj = ((dataPointer == IntPtr.Zero) ? null : new string((char*)(void*)dataPointer, 0, (data->Size >> 1) - 1));
1352 }
1353 }
1354
1355 [Conditional("DEBUG")]
1356 private unsafe static void AssertValidString(EventData* data)
1357 {
1358 char* ptr = (char*)(void*)data->DataPointer;
1359 int num = data->Size / 2 - 1;
1360 for (int i = 0; i < num; i++)
1361 {
1362 }
1363 }
1364
1366 {
1369 {
1370 if (eventDispatcher.m_Listener == listener)
1371 {
1372 return eventDispatcher;
1373 }
1374 }
1375 return eventDispatcher;
1376 }
1377
1378 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
1379 [RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")]
1380 private unsafe void WriteEventVarargs(int eventId, Guid* childActivityID, object[] args)
1381 {
1382 if (!IsEnabled())
1383 {
1384 return;
1385 }
1386 try
1387 {
1389 if (childActivityID != null && !reference.HasRelatedActivityID)
1390 {
1392 }
1394 Guid* ptr = null;
1397 EventOpcode opcode = (EventOpcode)reference.Descriptor.Opcode;
1398 EventActivityOptions activityOptions = reference.ActivityOptions;
1399 if (childActivityID == null && (activityOptions & EventActivityOptions.Disable) == 0)
1400 {
1401 switch (opcode)
1402 {
1403 case EventOpcode.Start:
1405 break;
1406 case EventOpcode.Stop:
1408 break;
1409 }
1410 if (activityId != Guid.Empty)
1411 {
1412 ptr = &activityId;
1413 }
1415 {
1417 }
1418 }
1419 if (reference.EnabledForETW || reference.EnabledForEventPipe)
1420 {
1422 {
1423 if (!m_etwProvider.WriteEvent(ref reference.Descriptor, reference.EventHandle, ptr, childActivityID, args))
1424 {
1426 }
1427 if (!m_eventPipeProvider.WriteEvent(ref reference.Descriptor, reference.EventHandle, ptr, childActivityID, args))
1428 {
1430 }
1431 }
1432 else
1433 {
1435 eventSourceOptions.Keywords = (EventKeywords)reference.Descriptor.Keywords;
1436 eventSourceOptions.Level = (EventLevel)reference.Descriptor.Level;
1437 eventSourceOptions.Opcode = (EventOpcode)reference.Descriptor.Opcode;
1439 WriteMultiMerge(reference.Name, ref options, reference.TraceLoggingEventTypes, ptr, childActivityID, args);
1440 }
1441 }
1442 if (m_Dispatchers != null && reference.EnabledForAnyListener)
1443 {
1445 {
1447 }
1449 {
1450 Payload = new ReadOnlyCollection<object>(args)
1451 };
1453 }
1454 }
1455 catch (Exception ex)
1456 {
1458 {
1459 throw;
1460 }
1462 }
1463 }
1464
1465 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
1466 [RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")]
1467 private object[] SerializeEventArgs(int eventId, object[] args)
1468 {
1470 int num = Math.Min(traceLoggingEventTypes.typeInfos.Length, args.Length);
1471 object[] array = new object[traceLoggingEventTypes.typeInfos.Length];
1472 for (int i = 0; i < num; i++)
1473 {
1474 array[i] = traceLoggingEventTypes.typeInfos[i].GetData(args[i]);
1475 }
1476 return array;
1477 }
1478
1479 private void LogEventArgsMismatches(int eventId, object[] args)
1480 {
1481 ParameterInfo[] parameters = m_eventData[eventId].Parameters;
1482 if (args.Length != parameters.Length)
1483 {
1485 return;
1486 }
1487 for (int i = 0; i < args.Length; i++)
1488 {
1489 Type parameterType = parameters[i].ParameterType;
1490 object obj = args[i];
1491 if ((obj != null && !parameterType.IsAssignableFrom(obj.GetType())) || (obj == null && parameterType.IsValueType && (!parameterType.IsGenericType || !(parameterType.GetGenericTypeDefinition() == typeof(Nullable<>)))))
1492 {
1494 break;
1495 }
1496 }
1497 }
1498
1500 {
1502 if (eventDataCount != reference.EventListenerParameterCount)
1503 {
1505 }
1506 if (eventDataCount == 0)
1507 {
1508 eventCallbackArgs.Payload = EventWrittenEventArgs.EmptyPayload;
1509 }
1510 else
1511 {
1512 object[] array = new object[Math.Min(eventDataCount, reference.Parameters.Length)];
1513 if (reference.AllParametersAreString)
1514 {
1515 int num = 0;
1516 while (num < array.Length)
1517 {
1519 array[num] = ((dataPointer == IntPtr.Zero) ? null : new string((char*)(void*)dataPointer, 0, (data->Size >> 1) - 1));
1520 num++;
1521 data++;
1522 }
1523 }
1524 else if (reference.AllParametersAreInt32)
1525 {
1526 int num2 = 0;
1527 while (num2 < array.Length)
1528 {
1529 array[num2] = *(int*)(void*)data->DataPointer;
1530 num2++;
1531 data++;
1532 }
1533 }
1534 else
1535 {
1536 DecodeObjects(array, reference.ParameterTypes, data);
1537 }
1538 eventCallbackArgs.Payload = new ReadOnlyCollection<object>(array);
1539 }
1541 }
1542
1544 {
1545 int eventId = eventCallbackArgs.EventId;
1546 Exception ex = null;
1548 {
1549 if (eventId == -1 || eventDispatcher.m_EventEnabled[eventId])
1550 {
1551 try
1552 {
1553 eventDispatcher.m_Listener.OnEventWritten(eventCallbackArgs);
1554 }
1555 catch (Exception ex2)
1556 {
1557 ReportOutOfBandMessage("ERROR: Exception during EventSource.OnEventWritten: " + ex2.Message);
1558 ex = ex2;
1559 }
1560 }
1561 }
1562 if (ex != null && ThrowOnEventWriteErrors)
1563 {
1564 throw new EventSourceException(ex);
1565 }
1566 }
1567
1568 private unsafe void WriteEventString(string msgString)
1569 {
1570 bool flag = true;
1571 flag &= m_etwProvider == null;
1572 if (flag & (m_eventPipeProvider == null))
1573 {
1574 return;
1575 }
1576 EventLevel eventLevel = EventLevel.LogAlways;
1577 long keywords = -1L;
1579 {
1581 eventSourceOptions.Keywords = (EventKeywords)keywords;
1582 eventSourceOptions.Level = eventLevel;
1585 WriteMultiMergeInner("EventSourceMessage", ref options, eventTypes, null, null, msgString);
1586 return;
1587 }
1588 if (m_rawManifest == null && m_outOfBandMessageCount == 1)
1589 {
1591 manifestBuilder.StartEvent("EventSourceMessage", new EventAttribute(0)
1592 {
1593 Level = eventLevel,
1594 Task = (EventTask)65534
1595 });
1596 manifestBuilder.AddEventParameter(typeof(string), "message");
1597 manifestBuilder.EndEvent();
1598 SendManifest(manifestBuilder.CreateManifest());
1599 }
1600 fixed (char* ptr = msgString)
1601 {
1602 EventDescriptor eventDescriptor = new EventDescriptor(0, 0, 0, (byte)eventLevel, 0, 0, keywords);
1604 eventData.Ptr = (ulong)ptr;
1605 eventData.Size = (uint)(2 * (msgString.Length + 1));
1606 eventData.Reserved = 0u;
1607 if (m_etwProvider != null)
1608 {
1609 m_etwProvider.WriteEvent(ref eventDescriptor, IntPtr.Zero, null, null, 1, (IntPtr)(&eventData));
1610 }
1611 if (m_eventPipeProvider == null)
1612 {
1613 return;
1614 }
1616 {
1617 if (m_createEventLock == null)
1618 {
1619 Interlocked.CompareExchange(ref m_createEventLock, new object(), null);
1620 }
1622 {
1624 {
1625 string eventName = "EventSourceMessage";
1627 eventParameterInfo.SetInfo("message", typeof(string));
1628 byte[] array = EventPipeMetadataGenerator.Instance.GenerateMetadata(0, eventName, keywords, (uint)eventLevel, 0u, EventOpcode.Info, new EventParameterInfo[1] { eventParameterInfo });
1629 uint metadataLength = ((array != null) ? ((uint)array.Length) : 0u);
1630 fixed (byte* pMetadata = array)
1631 {
1632 m_writeEventStringEventHandle = m_eventPipeProvider.m_eventProvider.DefineEventHandle(0u, eventName, keywords, 0u, (uint)eventLevel, pMetadata, metadataLength);
1633 }
1634 }
1635 }
1636 }
1638 }
1639 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The call to TraceLoggingEventTypes with the below parameter values are trim safe")]
1641 {
1642 return new TraceLoggingEventTypes("EventSourceMessage", EventTags.None, typeof(string));
1643 }
1644 }
1645
1646 private void WriteStringToAllListeners(string eventName, string msg)
1647 {
1649 eventWrittenEventArgs.EventName = eventName;
1650 eventWrittenEventArgs.Message = msg;
1651 eventWrittenEventArgs.Payload = new ReadOnlyCollection<object>(new object[1] { msg });
1652 eventWrittenEventArgs.PayloadNames = new ReadOnlyCollection<string>(new string[1] { "message" });
1655 {
1656 bool flag = false;
1657 if (eventDispatcher.m_EventEnabled == null)
1658 {
1659 flag = true;
1660 }
1661 else
1662 {
1663 for (int i = 0; i < eventDispatcher.m_EventEnabled.Length; i++)
1664 {
1665 if (eventDispatcher.m_EventEnabled[i])
1666 {
1667 flag = true;
1668 break;
1669 }
1670 }
1671 }
1672 try
1673 {
1674 if (flag)
1675 {
1676 eventDispatcher.m_Listener.OnEventWritten(eventData);
1677 }
1678 }
1679 catch
1680 {
1681 }
1682 }
1683 }
1684
1686 {
1687 if (!enable)
1688 {
1689 return false;
1690 }
1691 EventLevel level = (EventLevel)m_eventData[eventNum].Descriptor.Level;
1692 EventKeywords eventKeywords = (EventKeywords)(m_eventData[eventNum].Descriptor.Keywords & (long)(~SessionMask.All.ToEventKeywords()));
1693 EventChannel channel = (EventChannel)m_eventData[eventNum].Descriptor.Channel;
1694 return IsEnabledCommon(enable, currentLevel, currentMatchAnyKeyword, level, eventKeywords, channel);
1695 }
1696
1698 {
1699 if (!enabled)
1700 {
1701 return false;
1702 }
1703 if (currentLevel != 0 && currentLevel < eventLevel)
1704 {
1705 return false;
1706 }
1708 {
1709 if (eventChannel != 0 && m_channelData != null && m_channelData.Length > (int)eventChannel)
1710 {
1713 {
1714 return false;
1715 }
1716 }
1718 {
1719 return false;
1720 }
1721 }
1722 return true;
1723 }
1724
1725 [MethodImpl(MethodImplOptions.NoInlining)]
1726 private void ThrowEventSourceException(string eventName, Exception innerEx = null)
1727 {
1729 {
1730 return;
1731 }
1732 try
1733 {
1735 string text = "EventSourceException";
1736 if (eventName != null)
1737 {
1738 text = text + " while processing event \"" + eventName + "\"";
1739 }
1741 {
1742 case EventProvider.WriteEventErrorCode.EventTooBig:
1745 {
1747 }
1748 return;
1749 case EventProvider.WriteEventErrorCode.NoFreeBuffers:
1752 {
1754 }
1755 return;
1756 case EventProvider.WriteEventErrorCode.NullInput:
1759 {
1761 }
1762 return;
1763 case EventProvider.WriteEventErrorCode.TooManyArgs:
1766 {
1768 }
1769 return;
1770 }
1771 if (innerEx != null)
1772 {
1773 innerEx = innerEx.GetBaseException();
1774 ReportOutOfBandMessage(text + ": " + innerEx.GetType()?.ToString() + ":" + innerEx.Message);
1775 }
1776 else
1777 {
1779 }
1781 {
1782 throw new EventSourceException(innerEx);
1783 }
1784 }
1785 finally
1786 {
1788 }
1789 }
1790
1791 internal static EventOpcode GetOpcodeWithDefault(EventOpcode opcode, string eventName)
1792 {
1793 if (opcode == EventOpcode.Info && eventName != null)
1794 {
1795 if (eventName.EndsWith("Start", StringComparison.Ordinal))
1796 {
1797 return EventOpcode.Start;
1798 }
1799 if (eventName.EndsWith("Stop", StringComparison.Ordinal))
1800 {
1801 return EventOpcode.Stop;
1802 }
1803 }
1804 return opcode;
1805 }
1806
1807 internal void SendCommand(EventListener listener, EventProviderType eventProviderType, int perEventSourceSessionId, int etwSessionId, EventCommand command, bool enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary<string, string> commandArguments)
1808 {
1809 if (!IsSupported)
1810 {
1811 return;
1812 }
1813 EventCommandEventArgs eventCommandEventArgs = new EventCommandEventArgs(command, commandArguments, this, listener, eventProviderType, perEventSourceSessionId, etwSessionId, enable, level, matchAnyKeyword);
1815 {
1817 {
1818 m_deferredCommands = null;
1820 return;
1821 }
1822 if (m_deferredCommands == null)
1823 {
1825 return;
1826 }
1828 while (eventCommandEventArgs2.nextCommand != null)
1829 {
1831 }
1832 eventCommandEventArgs2.nextCommand = eventCommandEventArgs;
1833 }
1834 }
1835
1837 {
1838 if (!IsSupported || m_etwProvider == null || m_eventPipeProvider == null)
1839 {
1840 return;
1841 }
1843 try
1844 {
1846 commandArgs.dispatcher = GetDispatcher(commandArgs.listener);
1847 if (commandArgs.dispatcher == null && commandArgs.listener != null)
1848 {
1850 }
1851 if (commandArgs.Arguments == null)
1852 {
1853 IDictionary<string, string> dictionary2 = (commandArgs.Arguments = new Dictionary<string, string>());
1854 }
1855 if (commandArgs.Command == EventCommand.Update)
1856 {
1857 for (int i = 0; i < m_eventData.Length; i++)
1858 {
1859 EnableEventForDispatcher(commandArgs.dispatcher, commandArgs.eventProviderType, i, IsEnabledByDefault(i, commandArgs.enable, commandArgs.level, commandArgs.matchAnyKeyword));
1860 }
1861 if (commandArgs.enable)
1862 {
1864 {
1865 m_level = commandArgs.level;
1866 m_matchAnyKeyword = commandArgs.matchAnyKeyword;
1867 }
1868 else
1869 {
1870 if (commandArgs.level > m_level)
1871 {
1872 m_level = commandArgs.level;
1873 }
1874 if (commandArgs.matchAnyKeyword == EventKeywords.None)
1875 {
1877 }
1878 else if (m_matchAnyKeyword != EventKeywords.None)
1879 {
1880 m_matchAnyKeyword |= commandArgs.matchAnyKeyword;
1881 }
1882 }
1883 }
1884 bool flag = commandArgs.perEventSourceSessionId >= 0;
1885 if (commandArgs.perEventSourceSessionId == 0 && !commandArgs.enable)
1886 {
1887 flag = false;
1888 }
1889 if (commandArgs.listener == null)
1890 {
1891 if (!flag)
1892 {
1893 commandArgs.perEventSourceSessionId = -commandArgs.perEventSourceSessionId;
1894 }
1895 commandArgs.perEventSourceSessionId--;
1896 }
1897 commandArgs.Command = (flag ? EventCommand.Enable : EventCommand.Disable);
1898 if (flag && commandArgs.dispatcher == null && !SelfDescribingEvents)
1899 {
1901 }
1902 if (commandArgs.enable)
1903 {
1904 m_eventSourceEnabled = true;
1905 }
1907 m_eventCommandExecuted?.Invoke(this, commandArgs);
1908 if (commandArgs.enable)
1909 {
1910 return;
1911 }
1912 for (int j = 0; j < m_eventData.Length; j++)
1913 {
1914 bool enabledForAnyListener = false;
1916 {
1917 if (eventDispatcher.m_EventEnabled[j])
1918 {
1919 enabledForAnyListener = true;
1920 break;
1921 }
1922 }
1923 m_eventData[j].EnabledForAnyListener = enabledForAnyListener;
1924 }
1925 if (!AnyEventEnabled())
1926 {
1927 m_level = EventLevel.LogAlways;
1929 m_eventSourceEnabled = false;
1930 }
1931 }
1932 else
1933 {
1934 if (commandArgs.Command == EventCommand.SendManifest && m_rawManifest != null)
1935 {
1937 }
1939 m_eventCommandExecuted?.Invoke(this, commandArgs);
1940 }
1941 }
1942 catch (Exception ex)
1943 {
1944 ReportOutOfBandMessage("ERROR: Exception in Command Processing for EventSource " + Name + ": " + ex.Message);
1945 }
1946 }
1947
1948 internal bool EnableEventForDispatcher(EventDispatcher dispatcher, EventProviderType eventProviderType, int eventId, bool value)
1949 {
1950 if (!IsSupported)
1951 {
1952 return false;
1953 }
1954 if (dispatcher == null)
1955 {
1956 if (eventId >= m_eventData.Length)
1957 {
1958 return false;
1959 }
1960 if (m_etwProvider != null && eventProviderType == EventProviderType.ETW)
1961 {
1962 m_eventData[eventId].EnabledForETW = value;
1963 }
1964 if (m_eventPipeProvider != null && eventProviderType == EventProviderType.EventPipe)
1965 {
1966 m_eventData[eventId].EnabledForEventPipe = value;
1967 }
1968 }
1969 else
1970 {
1971 if (eventId >= dispatcher.m_EventEnabled.Length)
1972 {
1973 return false;
1974 }
1975 dispatcher.m_EventEnabled[eventId] = value;
1976 if (value)
1977 {
1978 m_eventData[eventId].EnabledForAnyListener = true;
1979 }
1980 }
1981 return true;
1982 }
1983
1984 private bool AnyEventEnabled()
1985 {
1986 for (int i = 0; i < m_eventData.Length; i++)
1987 {
1988 if (m_eventData[i].EnabledForETW || m_eventData[i].EnabledForAnyListener || m_eventData[i].EnabledForEventPipe)
1989 {
1990 return true;
1991 }
1992 }
1993 return false;
1994 }
1995
1997 {
1998 if (m_eventData != null)
1999 {
2000 return;
2001 }
2004 {
2006 {
2007 if (s_EventSource.TryGetTarget(out var target) && target.Guid == m_guid && !target.IsDisposed && target != this)
2008 {
2010 }
2011 }
2012 }
2014 {
2016 if (eventDispatcher2.m_EventEnabled == null)
2017 {
2018 eventDispatcher2.m_EventEnabled = new bool[m_eventData.Length];
2019 }
2020 }
2022 }
2023
2024 private unsafe void SendManifest(byte[] rawManifest)
2025 {
2026 if (rawManifest == null)
2027 {
2028 return;
2029 }
2030 fixed (byte* ptr2 = rawManifest)
2031 {
2032 EventDescriptor eventDescriptor = new EventDescriptor(65534, 1, 0, 0, 254, 65534, 72057594037927935L);
2034 manifestEnvelope.Format = ManifestEnvelope.ManifestFormats.SimpleXmlFormat;
2035 manifestEnvelope.MajorVersion = 1;
2036 manifestEnvelope.MinorVersion = 0;
2037 manifestEnvelope.Magic = 91;
2038 int num = rawManifest.Length;
2039 manifestEnvelope.ChunkNumber = 0;
2041 ptr->Ptr = (ulong)(&manifestEnvelope);
2042 ptr->Size = (uint)sizeof(ManifestEnvelope);
2043 ptr->Reserved = 0u;
2044 ptr[1].Ptr = (ulong)ptr2;
2045 ptr[1].Reserved = 0u;
2046 int num2 = 65280;
2047 while (true)
2048 {
2049 IL_00c7:
2050 manifestEnvelope.TotalChunks = (ushort)((num + (num2 - 1)) / num2);
2051 while (num > 0)
2052 {
2053 ptr[1].Size = (uint)Math.Min(num, num2);
2054 if (m_etwProvider != null && !m_etwProvider.WriteEvent(ref eventDescriptor, IntPtr.Zero, null, null, 2, (IntPtr)ptr))
2055 {
2056 if (EventProvider.GetLastWriteEventError() == EventProvider.WriteEventErrorCode.EventTooBig && manifestEnvelope.ChunkNumber == 0 && num2 > 256)
2057 {
2058 num2 /= 2;
2059 goto IL_00c7;
2060 }
2062 {
2063 ThrowEventSourceException("SendManifest");
2064 }
2065 break;
2066 }
2067 num -= num2;
2068 ptr[1].Ptr += (uint)num2;
2069 manifestEnvelope.ChunkNumber++;
2070 if (manifestEnvelope.ChunkNumber % 5 == 0)
2071 {
2072 Thread.Sleep(15);
2073 }
2074 }
2075 break;
2076 }
2077 }
2078 }
2079
2080 internal static bool IsCustomAttributeDefinedHelper(MemberInfo member, Type attributeType, EventManifestOptions flags = EventManifestOptions.None)
2081 {
2082 if (!member.Module.Assembly.ReflectionOnly && (flags & EventManifestOptions.AllowEventSourceOverride) == 0)
2083 {
2084 return member.IsDefined(attributeType, inherit: false);
2085 }
2087 {
2088 if (AttributeTypeNamesMatch(attributeType, customAttribute.Constructor.ReflectedType))
2089 {
2090 return true;
2091 }
2092 }
2093 return false;
2094 }
2095
2096 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:ReflectionToDynamicallyAccessedMembers", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which has dynamically accessed members requirements, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
2098 {
2099 if (!member.Module.Assembly.ReflectionOnly && (flags & EventManifestOptions.AllowEventSourceOverride) == 0)
2100 {
2101 return member.GetCustomAttribute(attributeType, inherit: false);
2102 }
2104 {
2105 if (!AttributeTypeNamesMatch(attributeType, customAttribute.Constructor.ReflectedType))
2106 {
2107 continue;
2108 }
2109 Attribute attribute = null;
2110 if (customAttribute.ConstructorArguments.Count == 1)
2111 {
2112 attribute = (Attribute)Activator.CreateInstance(attributeType, customAttribute.ConstructorArguments[0].Value);
2113 }
2114 else if (customAttribute.ConstructorArguments.Count == 0)
2115 {
2116 attribute = (Attribute)Activator.CreateInstance(attributeType);
2117 }
2118 if (attribute == null)
2119 {
2120 continue;
2121 }
2123 {
2124 PropertyInfo property = attributeType.GetProperty(namedArgument.MemberInfo.Name, BindingFlags.Instance | BindingFlags.Public);
2125 object obj = namedArgument.TypedValue.Value;
2126 if (property.PropertyType.IsEnum)
2127 {
2128 string value = obj.ToString();
2129 obj = Enum.Parse(property.PropertyType, value);
2130 }
2131 property.SetValue(attribute, obj, null);
2132 }
2133 return attribute;
2134 }
2135 return null;
2136 }
2137
2138 private static bool AttributeTypeNamesMatch(Type attributeType, Type reflectedAttributeType)
2139 {
2140 if (!(attributeType == reflectedAttributeType) && !string.Equals(attributeType.FullName, reflectedAttributeType.FullName, StringComparison.Ordinal))
2141 {
2142 if (string.Equals(attributeType.Name, reflectedAttributeType.Name, StringComparison.Ordinal) && attributeType.Namespace.EndsWith("Diagnostics.Tracing", StringComparison.Ordinal))
2143 {
2144 return reflectedAttributeType.Namespace.EndsWith("Diagnostics.Tracing", StringComparison.Ordinal);
2145 }
2146 return false;
2147 }
2148 return true;
2149 }
2150
2152 {
2154 if (type.BaseType == null)
2155 {
2156 return null;
2157 }
2158 do
2159 {
2160 type = type.BaseType;
2161 }
2162 while (type != null && type.IsAbstract);
2163 if (type != null)
2164 {
2166 {
2168 {
2169 return null;
2170 }
2171 }
2172 else if (type.Name != "EventSource")
2173 {
2174 return null;
2175 }
2176 }
2177 return type;
2178 }
2179
2180 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:ReflectionToDynamicallyAccessedMembers", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which has dynamically accessed members requirements, but its use of this method satisfies these requirements because it passes in the result of GetType with the same annotations.")]
2182 {
2184 bool flag = source == null || !source.SelfDescribingEvents;
2185 Exception ex = null;
2186 byte[] result = null;
2187 if (eventSourceType.IsAbstract && (flags & EventManifestOptions.Strict) == 0)
2188 {
2189 return null;
2190 }
2191 try
2192 {
2193 MethodInfo[] methods = eventSourceType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
2194 int num = 1;
2195 EventMetadata[] eventData = null;
2197 if (source != null || (flags & EventManifestOptions.Strict) != 0)
2198 {
2199 eventData = new EventMetadata[methods.Length + 1];
2200 eventData[0].Name = "";
2201 }
2202 ResourceManager resources = null;
2204 if (eventSourceAttribute != null && eventSourceAttribute.LocalizationResources != null)
2205 {
2206 resources = new ResourceManager(eventSourceAttribute.LocalizationResources, eventSourceType.Assembly);
2207 }
2208 manifestBuilder = ((source == null) ? new ManifestBuilder(GetName(eventSourceType, flags), GetGuid(eventSourceType), eventSourceDllName, resources, flags) : new ManifestBuilder(source.Name, source.Guid, eventSourceDllName, resources, flags));
2209 manifestBuilder.StartEvent("EventSourceMessage", new EventAttribute(0)
2210 {
2211 Level = EventLevel.LogAlways,
2212 Task = (EventTask)65534
2213 });
2214 manifestBuilder.AddEventParameter(typeof(string), "message");
2215 manifestBuilder.EndEvent();
2216 if ((flags & EventManifestOptions.Strict) != 0)
2217 {
2218 if (!(GetEventSourceBaseType(eventSourceType, (flags & EventManifestOptions.AllowEventSourceOverride) != 0, eventSourceType.Assembly.ReflectionOnly) != null))
2219 {
2221 }
2222 if (!eventSourceType.IsAbstract && !eventSourceType.IsSealed)
2223 {
2225 }
2226 }
2227 string[] array = new string[3] { "Keywords", "Tasks", "Opcodes" };
2228 foreach (string text in array)
2229 {
2230 Type nestedType = eventSourceType.GetNestedType(text);
2231 if (!(nestedType != null))
2232 {
2233 continue;
2234 }
2235 if (eventSourceType.IsAbstract)
2236 {
2238 continue;
2239 }
2240 FieldInfo[] fields = nestedType.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
2241 foreach (FieldInfo staticField in fields)
2242 {
2244 }
2245 }
2246 manifestBuilder.AddKeyword("Session3", 17592186044416uL);
2247 manifestBuilder.AddKeyword("Session2", 35184372088832uL);
2248 manifestBuilder.AddKeyword("Session1", 70368744177664uL);
2249 manifestBuilder.AddKeyword("Session0", 140737488355328uL);
2251 {
2252 foreach (MethodInfo methodInfo in methods)
2253 {
2254 ParameterInfo[] args = methodInfo.GetParameters();
2256 if (methodInfo.IsStatic)
2257 {
2258 continue;
2259 }
2260 if (eventSourceType.IsAbstract)
2261 {
2262 if (eventAttribute != null)
2263 {
2265 }
2266 continue;
2267 }
2268 if (eventAttribute == null)
2269 {
2270 if (methodInfo.ReturnType != typeof(void) || methodInfo.IsVirtual || IsCustomAttributeDefinedHelper(methodInfo, typeof(NonEventAttribute), flags))
2271 {
2272 continue;
2273 }
2276 }
2277 else if (eventAttribute.EventId <= 0)
2278 {
2280 continue;
2281 }
2282 if (methodInfo.Name.LastIndexOf('.') >= 0)
2283 {
2285 }
2286 num++;
2287 string name = methodInfo.Name;
2288 if (eventAttribute.Opcode == EventOpcode.Info)
2289 {
2290 bool flag2 = eventAttribute.Task == EventTask.None;
2291 if (flag2)
2292 {
2293 eventAttribute.Task = (EventTask)(65534 - eventAttribute.EventId);
2294 }
2295 if (!eventAttribute.IsOpcodeSet)
2296 {
2297 eventAttribute.Opcode = GetOpcodeWithDefault(EventOpcode.Info, name);
2298 }
2299 if (flag2)
2300 {
2301 if (eventAttribute.Opcode == EventOpcode.Start)
2302 {
2303 string text2 = name.Substring(0, name.Length - "Start".Length);
2304 if (string.Compare(name, 0, text2, 0, text2.Length) == 0 && string.Compare(name, text2.Length, "Start", 0, Math.Max(name.Length - text2.Length, "Start".Length)) == 0)
2305 {
2306 manifestBuilder.AddTask(text2, (int)eventAttribute.Task);
2307 }
2308 }
2309 else if (eventAttribute.Opcode == EventOpcode.Stop)
2310 {
2311 int num2 = eventAttribute.EventId - 1;
2312 if (eventData != null && num2 < eventData.Length)
2313 {
2315 string text3 = name.Substring(0, name.Length - "Stop".Length);
2316 if (eventMetadata.Descriptor.Opcode == 1 && string.Compare(eventMetadata.Name, 0, text3, 0, text3.Length) == 0 && string.Compare(eventMetadata.Name, text3.Length, "Start", 0, Math.Max(eventMetadata.Name.Length - text3.Length, "Start".Length)) == 0)
2317 {
2318 eventAttribute.Task = (EventTask)eventMetadata.Descriptor.Task;
2319 flag2 = false;
2320 }
2321 }
2322 if (flag2 && (flags & EventManifestOptions.Strict) != 0)
2323 {
2325 }
2326 }
2327 }
2328 }
2330 if (source == null || !source.SelfDescribingEvents)
2331 {
2332 manifestBuilder.StartEvent(name, eventAttribute);
2333 for (int l = 0; l < args.Length; l++)
2334 {
2335 manifestBuilder.AddEventParameter(args[l].ParameterType, args[l].Name);
2336 }
2337 manifestBuilder.EndEvent();
2338 }
2339 if (source == null && (flags & EventManifestOptions.Strict) == 0)
2340 {
2341 continue;
2342 }
2344 if (eventAttribute.Channel != 0)
2345 {
2346 eventAttribute.Keywords |= (EventKeywords)manifestBuilder.GetChannelKeyword(eventAttribute.Channel, (ulong)eventAttribute.Keywords);
2347 }
2348 if (manifestBuilder.HasResources)
2349 {
2350 string key = "event_" + name;
2351 string localizedMessage = manifestBuilder.GetLocalizedMessage(key, CultureInfo.CurrentUICulture, etwFormat: false);
2352 if (localizedMessage != null)
2353 {
2354 eventAttribute.Message = localizedMessage;
2355 }
2356 }
2358 }
2359 }
2361 if (source != null)
2362 {
2364 source.m_eventData = eventData;
2365 source.m_channelData = manifestBuilder.GetChannelData();
2366 }
2367 if (!eventSourceType.IsAbstract && (source == null || !source.SelfDescribingEvents))
2368 {
2369 flag = (flags & EventManifestOptions.OnlyIfNeededForRegistration) == 0 || manifestBuilder.GetChannelData().Length != 0;
2370 if (!flag && (flags & EventManifestOptions.Strict) == 0)
2371 {
2372 return null;
2373 }
2374 result = manifestBuilder.CreateManifest();
2375 }
2376 }
2377 catch (Exception ex2)
2378 {
2379 if ((flags & EventManifestOptions.Strict) == 0)
2380 {
2381 throw;
2382 }
2383 ex = ex2;
2384 }
2385 if ((flags & EventManifestOptions.Strict) != 0 && ((manifestBuilder != null && manifestBuilder.Errors.Count > 0) || ex != null))
2386 {
2387 string text4 = string.Empty;
2388 if (manifestBuilder != null && manifestBuilder.Errors.Count > 0)
2389 {
2390 bool flag3 = true;
2391 foreach (string error in manifestBuilder.Errors)
2392 {
2393 if (!flag3)
2394 {
2396 }
2397 flag3 = false;
2398 text4 += error;
2399 }
2400 }
2401 else
2402 {
2403 text4 = "Unexpected error: " + ex.Message;
2404 }
2405 throw new ArgumentException(text4, ex);
2406 }
2407 if (!flag)
2408 {
2409 return null;
2410 }
2411 return result;
2412 }
2413
2415 {
2416 if (args.Length != 0 && args[0].ParameterType == typeof(Guid) && string.Equals(args[0].Name, "relatedActivityId", StringComparison.OrdinalIgnoreCase))
2417 {
2418 ParameterInfo[] array = new ParameterInfo[args.Length - 1];
2419 Array.Copy(args, 1, array, 0, args.Length - 1);
2420 args = array;
2421 return true;
2422 }
2423 return false;
2424 }
2425
2427 {
2428 bool reflectionOnly = staticField.Module.Assembly.ReflectionOnly;
2429 Type fieldType = staticField.FieldType;
2431 {
2432 if (!(providerEnumKind != "Opcodes"))
2433 {
2434 int value = (int)staticField.GetRawConstantValue();
2435 manifest.AddOpcode(staticField.Name, value);
2436 return;
2437 }
2438 }
2440 {
2441 if (!(providerEnumKind != "Tasks"))
2442 {
2443 int value2 = (int)staticField.GetRawConstantValue();
2444 manifest.AddTask(staticField.Name, value2);
2445 return;
2446 }
2447 }
2448 else
2449 {
2451 {
2452 return;
2453 }
2454 if (!(providerEnumKind != "Keywords"))
2455 {
2456 ulong value3 = (ulong)(long)staticField.GetRawConstantValue();
2457 manifest.AddKeyword(staticField.Name, value3);
2458 return;
2459 }
2460 }
2462 }
2463
2465 {
2466 if (eventData.Length <= eventAttribute.EventId)
2467 {
2468 EventMetadata[] array = new EventMetadata[Math.Max(eventData.Length + 16, eventAttribute.EventId + 1)];
2470 eventData = array;
2471 }
2473 reference.Descriptor = new EventDescriptor(eventAttribute.EventId, eventAttribute.Version, (byte)eventAttribute.Channel, (byte)eventAttribute.Level, (byte)eventAttribute.Opcode, (int)eventAttribute.Task, (long)eventAttribute.Keywords | (long)SessionMask.All.ToEventKeywords());
2474 reference.Tags = eventAttribute.Tags;
2475 reference.Name = eventName;
2476 reference.Parameters = eventParameters;
2477 reference.Message = eventAttribute.Message;
2478 reference.ActivityOptions = eventAttribute.ActivityOptions;
2479 reference.HasRelatedActivityID = hasRelatedActivityID;
2480 reference.EventHandle = IntPtr.Zero;
2481 int num = eventParameters.Length;
2482 bool allParametersAreInt = true;
2483 bool allParametersAreString = true;
2485 {
2486 Type parameterType = parameterInfo.ParameterType;
2487 if (parameterType == typeof(string))
2488 {
2489 allParametersAreInt = false;
2490 continue;
2491 }
2492 if (parameterType == typeof(int) || (parameterType.IsEnum && Type.GetTypeCode(parameterType.GetEnumUnderlyingType()) <= TypeCode.UInt32))
2493 {
2494 allParametersAreString = false;
2495 continue;
2496 }
2497 if (parameterType == typeof(byte[]))
2498 {
2499 num++;
2500 }
2501 allParametersAreInt = false;
2502 allParametersAreString = false;
2503 }
2504 reference.AllParametersAreInt32 = allParametersAreInt;
2505 reference.AllParametersAreString = allParametersAreString;
2506 reference.EventListenerParameterCount = num;
2507 }
2508
2510 {
2511 int num = eventData.Length;
2512 while (0 < num)
2513 {
2514 num--;
2515 if (eventData[num].Descriptor.EventId != 0)
2516 {
2517 break;
2518 }
2519 }
2520 if (eventData.Length - num > 2)
2521 {
2522 EventMetadata[] array = new EventMetadata[num + 1];
2523 Array.Copy(eventData, array, array.Length);
2524 eventData = array;
2525 }
2526 }
2527
2528 internal void AddListener(EventListener listener)
2529 {
2531 {
2532 bool[] eventEnabled = null;
2533 if (m_eventData != null)
2534 {
2535 eventEnabled = new bool[m_eventData.Length];
2536 }
2538 listener.OnEventSourceCreated(this);
2539 }
2540 }
2541
2543 {
2544 int eventId = eventAttribute.EventId;
2545 string name = method.Name;
2548 {
2550 }
2551 if (eventId < eventData.Length && eventData[eventId].Descriptor.EventId != 0)
2552 {
2554 }
2555 for (int i = 0; i < eventData.Length; i++)
2556 {
2557 if (eventData[i].Name != null && eventData[i].Descriptor.Task == (int)eventAttribute.Task && (EventOpcode)eventData[i].Descriptor.Opcode == eventAttribute.Opcode)
2558 {
2559 manifest.ManifestError(SR.Format(SR.EventSource_TaskOpcodePairReused, name, eventId, eventData[i].Name, i));
2560 if ((options & EventManifestOptions.Strict) == 0)
2561 {
2562 break;
2563 }
2564 }
2565 }
2566 if (eventAttribute.Opcode != 0)
2567 {
2568 bool flag = false;
2569 if (eventAttribute.Task == EventTask.None)
2570 {
2571 flag = true;
2572 }
2573 else
2574 {
2575 EventTask eventTask = (EventTask)(65534 - eventId);
2576 if (eventAttribute.Opcode != EventOpcode.Start && eventAttribute.Opcode != EventOpcode.Stop && eventAttribute.Task == eventTask)
2577 {
2578 flag = true;
2579 }
2580 }
2581 if (flag)
2582 {
2584 }
2585 }
2586 if (eventsByName == null)
2587 {
2589 }
2590 if (eventsByName.ContainsKey(name))
2591 {
2592 manifest.ManifestError(SR.Format(SR.EventSource_EventNameReused, name), runtimeCritical: true);
2593 }
2594 eventsByName[name] = name;
2595 }
2596
2597 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The method calls MethodBase.GetMethodBody. Trimming application can change IL of various methodswhich can lead to change of behavior. This method only uses this to validate usage of event source APIs.In the worst case it will not be able to determine the value it's looking for and will not performany validation.")]
2599 {
2600 byte[] iLAsByteArray = method.GetMethodBody().GetILAsByteArray();
2601 int num = -1;
2602 for (int i = 0; i < iLAsByteArray.Length; i++)
2603 {
2604 switch (iLAsByteArray[i])
2605 {
2606 case 14:
2607 case 16:
2608 i++;
2609 continue;
2610 case 21:
2611 case 22:
2612 case 23:
2613 case 24:
2614 case 25:
2615 case 26:
2616 case 27:
2617 case 28:
2618 case 29:
2619 case 30:
2620 if (i > 0 && iLAsByteArray[i - 1] == 2)
2621 {
2622 num = iLAsByteArray[i] - 22;
2623 }
2624 continue;
2625 case 31:
2626 if (i > 0 && iLAsByteArray[i - 1] == 2)
2627 {
2628 num = iLAsByteArray[i + 1];
2629 }
2630 i++;
2631 continue;
2632 case 32:
2633 i += 4;
2634 continue;
2635 case 40:
2636 i += 4;
2637 if (num >= 0)
2638 {
2639 for (int j = i + 1; j < iLAsByteArray.Length; j++)
2640 {
2641 if (iLAsByteArray[j] == 42)
2642 {
2643 return num;
2644 }
2645 if (iLAsByteArray[j] != 0)
2646 {
2647 break;
2648 }
2649 }
2650 }
2651 num = -1;
2652 continue;
2653 case 44:
2654 case 45:
2655 num = -1;
2656 i++;
2657 continue;
2658 case 57:
2659 case 58:
2660 num = -1;
2661 i += 4;
2662 continue;
2663 case 140:
2664 case 141:
2665 i += 4;
2666 continue;
2667 case 254:
2668 i++;
2669 if (i < iLAsByteArray.Length && iLAsByteArray[i] < 6)
2670 {
2671 continue;
2672 }
2673 break;
2674 case 0:
2675 case 1:
2676 case 2:
2677 case 3:
2678 case 4:
2679 case 5:
2680 case 6:
2681 case 7:
2682 case 8:
2683 case 9:
2684 case 10:
2685 case 11:
2686 case 12:
2687 case 13:
2688 case 20:
2689 case 37:
2690 case 103:
2691 case 104:
2692 case 105:
2693 case 106:
2694 case 109:
2695 case 110:
2696 case 162:
2697 continue;
2698 }
2699 return -1;
2700 }
2701 return -1;
2702 }
2703
2704 internal void ReportOutOfBandMessage(string msg)
2705 {
2706 try
2707 {
2708 if (m_outOfBandMessageCount < 15)
2709 {
2711 }
2712 else
2713 {
2714 if (m_outOfBandMessageCount == 16)
2715 {
2716 return;
2717 }
2719 msg = "Reached message limit. End of EventSource error messages.";
2720 }
2721 Debugger.Log(0, null, "EventSource Error: " + msg + Environment.NewLine);
2722 WriteEventString(msg);
2723 WriteStringToAllListeners("EventSourceMessage", msg);
2724 }
2725 catch
2726 {
2727 }
2728 }
2729
2731 {
2732 if ((settings & (EventSourceSettings.EtwManifestEventFormat | EventSourceSettings.EtwSelfDescribingEventFormat)) == (EventSourceSettings.EtwManifestEventFormat | EventSourceSettings.EtwSelfDescribingEventFormat))
2733 {
2735 }
2736 if ((settings & (EventSourceSettings.EtwManifestEventFormat | EventSourceSettings.EtwSelfDescribingEventFormat)) == 0)
2737 {
2738 settings |= EventSourceSettings.EtwSelfDescribingEventFormat;
2739 }
2740 return settings;
2741 }
2742
2747
2752
2755 {
2756 if (eventSourceName == null)
2757 {
2758 throw new ArgumentNullException("eventSourceName");
2759 }
2760 }
2761
2762 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
2763 public unsafe void Write(string? eventName)
2764 {
2765 if (IsEnabled())
2766 {
2768 WriteImpl(eventName, ref options, null, null, null, SimpleEventTypes<EmptyStruct>.Instance);
2769 }
2770 }
2771
2772 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
2773 public unsafe void Write(string? eventName, EventSourceOptions options)
2774 {
2775 if (IsEnabled())
2776 {
2777 WriteImpl(eventName, ref options, null, null, null, SimpleEventTypes<EmptyStruct>.Instance);
2778 }
2779 }
2780
2781 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
2782 [RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")]
2783 public unsafe void Write<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(string? eventName, T data)
2784 {
2785 if (IsEnabled())
2786 {
2788 WriteImpl(eventName, ref options, data, null, null, SimpleEventTypes<T>.Instance);
2789 }
2790 }
2791
2792 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
2793 [RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")]
2794 public unsafe void Write<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(string? eventName, EventSourceOptions options, T data)
2795 {
2796 if (IsEnabled())
2797 {
2798 WriteImpl(eventName, ref options, data, null, null, SimpleEventTypes<T>.Instance);
2799 }
2800 }
2801
2802 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
2803 [RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")]
2804 public unsafe void Write<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(string? eventName, ref EventSourceOptions options, ref T data)
2805 {
2806 if (IsEnabled())
2807 {
2808 WriteImpl(eventName, ref options, data, null, null, SimpleEventTypes<T>.Instance);
2809 }
2810 }
2811
2812 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
2813 [RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")]
2815 {
2816 if (!IsEnabled())
2817 {
2818 return;
2819 }
2821 {
2823 {
2824 WriteImpl(eventName, ref options, data, pActivityId, (relatedActivityId == Guid.Empty) ? null : ptr, SimpleEventTypes<T>.Instance);
2825 }
2826 }
2827 }
2828
2830 {
2831 if (IsEnabled())
2832 {
2833 byte level = (((options.valuesSet & 4u) != 0) ? options.level : eventTypes.level);
2834 EventKeywords keywords = ((((uint)options.valuesSet & (true ? 1u : 0u)) != 0) ? options.keywords : eventTypes.keywords);
2835 if (IsEnabled((EventLevel)level, keywords))
2836 {
2838 }
2839 }
2840 }
2841
2843 {
2844 int num = 0;
2845 byte level = (((options.valuesSet & 4u) != 0) ? options.level : eventTypes.level);
2846 byte opcode = (((options.valuesSet & 8u) != 0) ? options.opcode : eventTypes.opcode);
2847 EventTags tags = (((options.valuesSet & 2u) != 0) ? options.tags : eventTypes.Tags);
2848 EventKeywords keywords = ((((uint)options.valuesSet & (true ? 1u : 0u)) != 0) ? options.keywords : eventTypes.keywords);
2849 NameInfo nameInfo = eventTypes.GetNameInfo(eventName ?? eventTypes.Name, tags);
2850 if (nameInfo == null)
2851 {
2852 return;
2853 }
2854 num = nameInfo.identity;
2855 EventDescriptor eventDescriptor = new EventDescriptor(num, level, opcode, (long)keywords);
2857 int pinCount = eventTypes.pinCount;
2858 byte* scratch = stackalloc byte[(int)(uint)eventTypes.scratchSize];
2859 EventData* ptr = stackalloc EventData[eventTypes.dataCount + 3];
2860 for (int i = 0; i < eventTypes.dataCount + 3; i++)
2861 {
2862 ptr[i] = default(EventData);
2863 }
2864 GCHandle* ptr2 = stackalloc GCHandle[pinCount];
2865 for (int j = 0; j < pinCount; j++)
2866 {
2867 ptr2[j] = default(GCHandle);
2868 }
2871 {
2872 fixed (byte* pointer2 = nameInfo.nameMetadata)
2873 {
2874 fixed (byte* pointer3 = eventTypes.typeMetadata)
2875 {
2876 ptr->SetMetadata(pointer, providerMetadata.Length, 2);
2877 ptr[1].SetMetadata(pointer2, nameInfo.nameMetadata.Length, 1);
2878 ptr[2].SetMetadata(pointer3, eventTypes.typeMetadata.Length, 1);
2879 try
2880 {
2881 DataCollector.ThreadInstance.Enable(scratch, eventTypes.scratchSize, ptr + 3, eventTypes.dataCount, ptr2, pinCount);
2882 for (int k = 0; k < eventTypes.typeInfos.Length; k++)
2883 {
2885 traceLoggingTypeInfo.WriteData(traceLoggingTypeInfo.PropertyValueFactory(values[k]));
2886 }
2888 }
2889 finally
2890 {
2891 WriteCleanup(ptr2, pinCount);
2892 }
2893 }
2894 }
2895 }
2896 }
2897
2899 {
2900 if (!IsEnabled())
2901 {
2902 return;
2903 }
2905 {
2906 EventDescriptor descriptor;
2907 NameInfo nameInfo = UpdateDescriptor(eventName, eventTypes, ref options, out descriptor);
2908 if (nameInfo == null)
2909 {
2910 return;
2911 }
2913 int num = eventTypes.dataCount + eventTypes.typeInfos.Length * 2 + 3;
2915 for (int i = 0; i < num; i++)
2916 {
2917 ptr[i] = default(EventData);
2918 }
2921 {
2922 fixed (byte* pointer2 = nameInfo.nameMetadata)
2923 {
2924 fixed (byte* pointer3 = eventTypes.typeMetadata)
2925 {
2926 ptr->SetMetadata(pointer, providerMetadata.Length, 2);
2927 ptr[1].SetMetadata(pointer2, nameInfo.nameMetadata.Length, 1);
2928 ptr[2].SetMetadata(pointer3, eventTypes.typeMetadata.Length, 1);
2929 int num2 = 3;
2930 for (int j = 0; j < eventTypes.typeInfos.Length; j++)
2931 {
2932 ptr[num2].m_Ptr = data[j].m_Ptr;
2933 ptr[num2].m_Size = data[j].m_Size;
2934 if (data[j].m_Size == 4 && eventTypes.typeInfos[j].DataType == typeof(bool))
2935 {
2936 ptr[num2].m_Size = 1;
2937 }
2938 num2++;
2939 }
2941 }
2942 }
2943 }
2944 }
2945 }
2946
2948 {
2949 try
2950 {
2952 {
2953 options.Opcode = (options.IsOpcodeSet ? options.Opcode : GetOpcodeWithDefault(options.Opcode, eventName));
2954 EventDescriptor descriptor;
2955 NameInfo nameInfo = UpdateDescriptor(eventName, eventTypes, ref options, out descriptor);
2956 if (nameInfo == null)
2957 {
2958 return;
2959 }
2961 int pinCount = eventTypes.pinCount;
2962 byte* scratch = stackalloc byte[(int)(uint)eventTypes.scratchSize];
2963 EventData* ptr = stackalloc EventData[eventTypes.dataCount + 3];
2964 for (int i = 0; i < eventTypes.dataCount + 3; i++)
2965 {
2966 ptr[i] = default(EventData);
2967 }
2968 GCHandle* ptr2 = stackalloc GCHandle[pinCount];
2969 for (int j = 0; j < pinCount; j++)
2970 {
2971 ptr2[j] = default(GCHandle);
2972 }
2975 {
2976 fixed (byte* pointer2 = nameInfo.nameMetadata)
2977 {
2978 fixed (byte* pointer3 = eventTypes.typeMetadata)
2979 {
2980 ptr->SetMetadata(pointer, providerMetadata.Length, 2);
2981 ptr[1].SetMetadata(pointer2, nameInfo.nameMetadata.Length, 1);
2982 ptr[2].SetMetadata(pointer3, eventTypes.typeMetadata.Length, 1);
2983 EventOpcode opcode = (EventOpcode)descriptor.Opcode;
2986 if (pActivityId == null && pRelatedActivityId == null && (options.ActivityOptions & EventActivityOptions.Disable) == 0)
2987 {
2988 switch (opcode)
2989 {
2990 case EventOpcode.Start:
2991 m_activityTracker.OnStart(m_name, eventName, 0, ref activityId, ref relatedActivityId, options.ActivityOptions);
2992 break;
2993 case EventOpcode.Stop:
2995 break;
2996 }
2997 if (activityId != Guid.Empty)
2998 {
3000 }
3002 {
3004 }
3005 }
3006 try
3007 {
3008 DataCollector.ThreadInstance.Enable(scratch, eventTypes.scratchSize, ptr + 3, eventTypes.dataCount, ptr2, pinCount);
3010 traceLoggingTypeInfo.WriteData(traceLoggingTypeInfo.PropertyValueFactory(data));
3012 if (m_Dispatchers != null)
3013 {
3014 EventPayload payload = (EventPayload)eventTypes.typeInfos[0].GetData(data);
3015 WriteToAllListeners(eventName, ref descriptor, nameInfo.tags, pActivityId, pRelatedActivityId, payload);
3016 }
3017 }
3018 catch (Exception ex)
3019 {
3021 {
3022 throw;
3023 }
3024 ThrowEventSourceException(eventName, ex);
3025 }
3026 finally
3027 {
3028 WriteCleanup(ptr2, pinCount);
3029 }
3030 }
3031 }
3032 }
3033 }
3034 }
3035 catch (Exception ex2)
3036 {
3038 {
3039 throw;
3040 }
3041 ThrowEventSourceException(eventName, ex2);
3042 }
3043 }
3044
3046 {
3048 {
3049 EventName = eventName,
3050 Level = (EventLevel)eventDescriptor.Level,
3051 Keywords = (EventKeywords)eventDescriptor.Keywords,
3052 Opcode = (EventOpcode)eventDescriptor.Opcode,
3053 Tags = tags
3054 };
3055 if (payload != null)
3056 {
3057 eventWrittenEventArgs.Payload = new ReadOnlyCollection<object>((IList<object>)payload.Values);
3058 eventWrittenEventArgs.PayloadNames = new ReadOnlyCollection<string>((IList<string>)payload.Keys);
3059 }
3061 }
3062
3063 [NonEvent]
3064 private unsafe static void WriteCleanup(GCHandle* pPins, int cPins)
3065 {
3066 DataCollector.ThreadInstance.Disable();
3067 for (int i = 0; i < cPins; i++)
3068 {
3069 if (pPins[i].IsAllocated)
3070 {
3071 pPins[i].Free();
3072 }
3073 }
3074 }
3075
3077 {
3078 if (ProviderMetadata.Length > 0)
3079 {
3080 return;
3081 }
3082 if (m_traits != null)
3083 {
3084 List<byte> list = new List<byte>(100);
3085 for (int i = 0; i < m_traits.Length - 1; i += 2)
3086 {
3087 if (!m_traits[i].StartsWith("ETW_", StringComparison.Ordinal))
3088 {
3089 continue;
3090 }
3091 string text = m_traits[i].Substring(4);
3092 if (!byte.TryParse(text, out var result))
3093 {
3094 if (!(text == "GROUP"))
3095 {
3097 }
3098 result = 1;
3099 }
3100 string value = m_traits[i + 1];
3101 int count = list.Count;
3102 list.Add(0);
3103 list.Add(0);
3104 list.Add(result);
3105 int num = AddValueToMetaData(list, value) + 3;
3106 list[count] = (byte)num;
3107 list[count + 1] = (byte)(num >> 8);
3108 }
3109 byte[] array = Statics.MetadataForString(Name, 0, list.Count, 0);
3110 int num2 = array.Length - list.Count;
3111 foreach (byte item in list)
3112 {
3113 array[num2++] = item;
3114 }
3116 }
3117 else
3118 {
3120 }
3121 }
3122
3123 private static int AddValueToMetaData(List<byte> metaData, string value)
3124 {
3125 if (value.Length == 0)
3126 {
3127 return 0;
3128 }
3129 int count = metaData.Count;
3130 char c = value[0];
3131 switch (c)
3132 {
3133 case '@':
3134 metaData.AddRange(Encoding.UTF8.GetBytes(value.Substring(1)));
3135 break;
3136 case '{':
3137 metaData.AddRange(new Guid(value).ToByteArray());
3138 break;
3139 case '#':
3140 {
3141 for (int i = 1; i < value.Length; i++)
3142 {
3143 if (value[i] != ' ')
3144 {
3145 if (i + 1 >= value.Length)
3146 {
3147 throw new ArgumentException(SR.EventSource_EvenHexDigits, "traits");
3148 }
3149 metaData.Add((byte)(HexDigit(value[i]) * 16 + HexDigit(value[i + 1])));
3150 i++;
3151 }
3152 }
3153 break;
3154 }
3155 default:
3156 if ('A' <= c || ' ' == c)
3157 {
3158 metaData.AddRange(Encoding.UTF8.GetBytes(value));
3159 break;
3160 }
3162 }
3163 return metaData.Count - count;
3164 }
3165
3166 private static int HexDigit(char c)
3167 {
3168 if ('0' <= c && c <= '9')
3169 {
3170 return c - 48;
3171 }
3172 if ('a' <= c)
3173 {
3174 c = (char)(c - 32);
3175 }
3176 if ('A' <= c && c <= 'F')
3177 {
3178 return c - 65 + 10;
3179 }
3180 throw new ArgumentException(SR.Format(SR.EventSource_BadHexDigit, c), "traits");
3181 }
3182
3184 {
3185 NameInfo nameInfo = null;
3186 int traceloggingId = 0;
3187 byte level = (((options.valuesSet & 4u) != 0) ? options.level : eventInfo.level);
3188 byte opcode = (((options.valuesSet & 8u) != 0) ? options.opcode : eventInfo.opcode);
3189 EventTags tags = (((options.valuesSet & 2u) != 0) ? options.tags : eventInfo.Tags);
3190 EventKeywords keywords = ((((uint)options.valuesSet & (true ? 1u : 0u)) != 0) ? options.keywords : eventInfo.keywords);
3191 if (IsEnabled((EventLevel)level, keywords))
3192 {
3193 nameInfo = eventInfo.GetNameInfo(name ?? eventInfo.Name, tags);
3194 traceloggingId = nameInfo.identity;
3195 }
3196 descriptor = new EventDescriptor(traceloggingId, level, opcode, (long)keywords);
3197 return nameInfo;
3198 }
3199}
static int EventActivityIdControl(ActivityControl ControlCode, ref Guid ActivityId)
static ? object CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture)
Definition Activator.cs:17
static bool TryGetSwitch(string switchName, out bool isEnabled)
Definition AppContext.cs:74
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
void AddRange(IEnumerable< KeyValuePair< TKey, TValue > > collection)
void Add(TKey key, TValue value)
static ? Delegate Remove(Delegate? source, Delegate? value)
Definition Delegate.cs:463
static ? Delegate Combine(Delegate? a, Delegate? b)
Definition Delegate.cs:379
static void Log(int level, string? category, string? message)
Definition Debugger.cs:55
void OnStart(string providerName, string activityName, int task, ref Guid activityId, ref Guid relatedActivityId, EventActivityOptions options, bool useTplSource=true)
void OnStop(string providerName, string activityName, int task, ref Guid activityId, bool useTplSource=true)
virtual void OnEventSourceCreated(EventSource eventSource)
static void AddEventSource(EventSource newEventSource)
static List< WeakReference< EventSource > > s_EventSources
static int EventActivityIdControl(Interop.Advapi32.ActivityControl ControlCode, ref Guid ActivityId)
static WriteEventErrorCode GetLastWriteEventError()
OverrideEventProvider(EventSource eventSource, EventProviderType providerType)
override void OnControllerCommand(ControllerCommand command, IDictionary< string, string > arguments, int perEventSourceSessionId, int etwSessionId)
void SendCommand(EventListener listener, EventProviderType eventProviderType, int perEventSourceSessionId, int etwSessionId, EventCommand command, bool enable, EventLevel level, EventKeywords matchAnyKeyword, IDictionary< string, string > commandArguments)
unsafe void WriteEvent(int eventId, long arg1, byte[]? arg2)
unsafe void WriteEvent(int eventId, string? arg1, int arg2)
unsafe void WriteEventWithRelatedActivityId(int eventId, Guid relatedActivityId, params object?[] args)
static void AddProviderEnumKind(ManifestBuilder manifest, FieldInfo staticField, string providerEnumKind)
static EventSourceSettings ValidateSettings(EventSourceSettings settings)
unsafe void WriteMultiMergeInner(string eventName, ref EventSourceOptions options, TraceLoggingEventTypes eventTypes, Guid *activityID, Guid *childActivityID, params object[] values)
unsafe void WriteEventCore(int eventId, int eventDataCount, EventData *data)
void DispatchToAllListeners(EventWrittenEventArgs eventCallbackArgs)
void WriteStringToAllListeners(string eventName, string msg)
EventHandler< EventCommandEventArgs >? EventCommandExecuted
void LogEventArgsMismatches(int eventId, object[] args)
static Guid GenerateGuidFromName(string name)
unsafe void WriteEvent(int eventId, string? arg1, string? arg2)
static byte[] CreateManifestAndDescriptors([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type eventSourceType, string eventSourceDllName, EventSource source, EventManifestOptions flags=EventManifestOptions.None)
virtual void Dispose(bool disposing)
bool IsEnabledCommon(bool enabled, EventLevel currentLevel, EventKeywords currentMatchAnyKeyword, EventLevel eventLevel, EventKeywords eventKeywords, EventChannel eventChannel)
static Guid GetGuid(Type eventSourceType)
EventCommandEventArgs m_deferredCommands
static string GetName(Type eventSourceType)
unsafe void SendManifest(byte[] rawManifest)
bool IsEnabled(EventLevel level, EventKeywords keywords, EventChannel channel)
static int AddValueToMetaData(List< byte > metaData, string value)
EventSource(Guid eventSourceGuid, string eventSourceName)
unsafe void WriteToAllListeners(string eventName, ref EventDescriptor eventDescriptor, EventTags tags, Guid *pActivityId, Guid *pChildActivityId, EventPayload payload)
unsafe void Write(string? eventName)
EventSource(bool throwOnEventWriteErrors)
static Attribute GetCustomAttributeHelper(MemberInfo member, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.PublicProperties)] Type attributeType, EventManifestOptions flags=EventManifestOptions.None)
NameInfo UpdateDescriptor(string name, TraceLoggingEventTypes eventInfo, ref EventSourceOptions options, out EventDescriptor descriptor)
void AddListener(EventListener listener)
unsafe void WriteEvent(int eventId, long arg1, string? arg2)
static void DebugCheckEvent(ref Dictionary< string, string > eventsByName, EventMetadata[] eventData, MethodInfo method, EventAttribute eventAttribute, ManifestBuilder manifest, EventManifestOptions options)
unsafe void WriteEvent(int eventId, long arg1)
static void TrimEventDescriptors(ref EventMetadata[] eventData)
readonly TraceLoggingEventHandleTable m_eventHandleTable
virtual ReadOnlySpan< byte > ProviderMetadata
unsafe void WriteEvent(int eventId, string? arg1, int arg2, int arg3)
volatile OverrideEventProvider m_eventPipeProvider
unsafe void Initialize(Guid eventSourceGuid, string eventSourceName, string[] traits)
static Type GetEventSourceBaseType(Type eventSourceType, bool allowEventSourceOverride, bool reflectionOnly)
volatile EventMetadata[] m_eventData
unsafe void WriteEvent(int eventId, int arg1)
unsafe void WriteEvent(int eventId, int arg1, int arg2)
unsafe void WriteImpl(string eventName, ref EventSourceOptions options, object data, Guid *pActivityId, Guid *pRelatedActivityId, TraceLoggingEventTypes eventTypes)
unsafe void WriteEvent(int eventId, string? arg1, long arg2)
unsafe void WriteEventRaw(string eventName, ref EventDescriptor eventDescriptor, IntPtr eventHandle, Guid *activityID, Guid *relatedActivityID, int dataCount, IntPtr data)
EventSource(string eventSourceName, EventSourceSettings config)
virtual void OnEventCommand(EventCommandEventArgs command)
EventSource(string eventSourceName)
static bool AttributeTypeNamesMatch(Type attributeType, Type reflectedAttributeType)
static void SetCurrentThreadActivityId(Guid activityId)
unsafe void WriteEvent(int eventId, int arg1, string? arg2)
unsafe void WriteEvent(int eventId, params object?[] args)
static EventOpcode GetOpcodeWithDefault(EventOpcode opcode, string eventName)
bool EnableEventForDispatcher(EventDispatcher dispatcher, EventProviderType eventProviderType, int eventId, bool value)
unsafe void WriteEvent(int eventId, long arg1, long arg2, long arg3)
EventSource(EventSourceSettings settings, params string[]? traits)
static void SendCommand(EventSource eventSource, EventCommand command, IDictionary< string, string?>? commandArguments)
static ? string GenerateManifest([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type eventSourceType, string? assemblyPathToIncludeInManifest, EventManifestOptions flags)
static int GetHelperCallFirstArg(MethodInfo method)
static bool IsCustomAttributeDefinedHelper(MemberInfo member, Type attributeType, EventManifestOptions flags=EventManifestOptions.None)
static IEnumerable< EventSource > GetSources()
static string GetName(Type eventSourceType, EventManifestOptions flags)
unsafe void WriteEventVarargs(int eventId, Guid *childActivityID, object[] args)
volatile OverrideEventProvider m_etwProvider
static unsafe void DecodeObjects(object[] decodedObjects, Type[] parameterTypes, EventData *data)
EventSource(EventSourceSettings settings)
unsafe void WriteEventWithRelatedActivityIdCore(int eventId, Guid *relatedActivityId, int eventDataCount, EventData *data)
unsafe void WriteToAllListeners(EventWrittenEventArgs eventCallbackArgs, int eventDataCount, EventData *data)
EventDispatcher GetDispatcher(EventListener listener)
static readonly bool AllowDuplicateSourceNames
EventSource(Guid eventSourceGuid, string eventSourceName, EventSourceSettings settings, string[] traits=null)
static void SetCurrentThreadActivityId(Guid activityId, out Guid oldActivityThatWillContinue)
volatile EventDispatcher m_Dispatchers
unsafe void WriteEvent(int eventId, long arg1, long arg2)
EventHandler< EventCommandEventArgs > m_eventCommandExecuted
const DynamicallyAccessedMemberTypes ManifestMemberTypes
object[] SerializeEventArgs(int eventId, object[] args)
unsafe void Write(string? eventName, EventSourceOptions options)
EventSource(string eventSourceName, EventSourceSettings config, params string[]? traits)
static void AddEventDescriptor([NotNull] ref EventMetadata[] eventData, string eventName, EventAttribute eventAttribute, ParameterInfo[] eventParameters, bool hasRelatedActivityID)
static unsafe void WriteCleanup(GCHandle *pPins, int cPins)
static ? string GenerateManifest([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type eventSourceType, string? assemblyPathToIncludeInManifest)
unsafe void WriteEvent(int eventId, string? arg1)
unsafe void WriteEvent(int eventId, string? arg1, string? arg2, string? arg3)
void DoCommand(EventCommandEventArgs commandArgs)
unsafe void WriteEvent(int eventId, int arg1, int arg2, int arg3)
static bool RemoveFirstArgIfRelatedActivityId(ref ParameterInfo[] args)
unsafe void WriteEvent(int eventId, byte[]? arg1)
void ThrowEventSourceException(string eventName, Exception innerEx=null)
readonly EventSourceSettings m_config
bool IsEnabled(EventLevel level, EventKeywords keywords)
unsafe void WriteMultiMerge(string eventName, ref EventSourceOptions options, TraceLoggingEventTypes eventTypes, Guid *activityID, Guid *childActivityID, EventData *data)
unsafe void WriteEvent(int eventId)
unsafe void WriteMultiMerge(string eventName, ref EventSourceOptions options, TraceLoggingEventTypes eventTypes, Guid *activityID, Guid *childActivityID, params object[] values)
static unsafe void AssertValidString(EventData *data)
unsafe void WriteEventString(string msgString)
bool IsEnabledByDefault(int eventNum, bool enable, EventLevel currentLevel, EventKeywords currentMatchAnyKeyword)
static readonly ReadOnlyCollection< object > EmptyPayload
static void ReserveEventIDsBelow(int eventId)
Definition NameInfo.cs:18
static byte[] MetadataForString(string name, int prefixSize, int suffixSize, int additionalSize)
Definition Statics.cs:17
static object Parse(Type enumType, string value)
Definition Enum.cs:368
static string NewLine
static bool IsWindows8OrAbove
static void SuppressFinalize(object obj)
Definition GC.cs:202
Definition GC.cs:8
static CultureInfo CurrentUICulture
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static IList< CustomAttributeData > GetCustomAttributes(MemberInfo target)
bool IsDefined(Type attributeType, bool inherit)
static void Copy(int[] source, int startIndex, IntPtr destination, int length)
Definition Marshal.cs:800
static string EventSource_EventNameReused
Definition SR.cs:1208
static string EventSource_MismatchIdToWriteEvent
Definition SR.cs:1244
static string EventSource_EnumKindMismatch
Definition SR.cs:1196
static string EventSource_EventMustHaveTaskIfNonDefaultOpcode
Definition SR.cs:1204
static string EventSource_EventTooBig
Definition SR.cs:1214
static string EventSource_InvalidEventFormat
Definition SR.cs:1230
static string EventSource_BadHexDigit
Definition SR.cs:1188
static string EventSource_TypeMustDeriveFromEventSource
Definition SR.cs:1290
static string EventSource_NeedName
Definition SR.cs:1248
static string EventSource_TaskOpcodePairReused
Definition SR.cs:1278
static string EventSource_EventMustNotBeExplicitImplementation
Definition SR.cs:1206
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string EventSource_IllegalValue
Definition SR.cs:1224
static string EventSource_ListenerNotFound
Definition SR.cs:1238
static string EventSource_TraitEven
Definition SR.cs:1286
static string EventSource_TypeMustBeSealedOrAbstract
Definition SR.cs:1288
static string EventSource_NoFreeBuffers
Definition SR.cs:1252
static string EventSource_NoRelatedActivityId
Definition SR.cs:1256
static string EventSource_VarArgsParameterMismatch
Definition SR.cs:1304
static string EventSource_AbstractMustNotDeclareKTOC
Definition SR.cs:1184
static string EventSource_AbstractMustNotDeclareEventMethods
Definition SR.cs:1182
static string EventSource_NeedGuid
Definition SR.cs:1246
static string EventSource_EventParametersMismatch
Definition SR.cs:1210
static string EventSource_ToString
Definition SR.cs:1284
static string EventSource_InvalidCommand
Definition SR.cs:1228
static string EventSource_EventSourceGuidInUse
Definition SR.cs:1212
static string EventSource_NullInput
Definition SR.cs:1266
static string EventSource_NeedPositiveId
Definition SR.cs:1250
static string EventSource_EvenHexDigits
Definition SR.cs:1198
static string EventSource_EventIdReused
Definition SR.cs:1202
static string EventSource_UnknownEtwTrait
Definition SR.cs:1298
static string EventSource_TooManyArgs
Definition SR.cs:1280
static string Argument_InvalidTypeName
Definition SR.cs:750
static string EventSource_StopsFollowStarts
Definition SR.cs:1274
Definition SR.cs:7
static Encoding BigEndianUnicode
Definition Encoding.cs:521
static Encoding UTF8
Definition Encoding.cs:526
static int CompareExchange(ref int location1, int value, int comparand)
static readonly TplEventSource Log
static void Sleep(int millisecondsTimeout)
Definition Thread.cs:658
static TypeCode GetTypeCode(Type? type)
Definition Type.cs:919
string? Namespace
Definition Type.cs:43
string? FullName
Definition Type.cs:47
TypeCode
Definition TypeCode.cs:4
unsafe void SetMetadata(byte *pointer, int size, int reserved)
static bool TryParse([NotNullWhen(true)] string? input, out Guid result)
Definition Guid.cs:206
static readonly Guid Empty
Definition Guid.cs:86
static int Size
Definition IntPtr.cs:21
static readonly IntPtr Zero
Definition IntPtr.cs:18