Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DiagnosticSourceEventSource.cs
Go to the documentation of this file.
8
9namespace System.Diagnostics;
10
11[EventSource(Name = "Microsoft-Diagnostics-DiagnosticSource")]
12[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:ReflectionToRequiresUnreferencedCode", Justification = "In EventSource, 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.")]
13[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2115:ReflectionToDynamicallyAccessedMembers", Justification = "In EventSource, 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.")]
15{
16 public static class Keywords
17 {
19
20 public const EventKeywords Events = (EventKeywords)2L;
21
23
25
27 }
28
29 [Flags]
30 internal enum ActivityEvents
31 {
32 None = 0,
33 ActivityStart = 1,
34 ActivityStop = 2,
35 All = 3
36 }
37
38 internal sealed class FilterAndTransform
39 {
41
43
45
46 private readonly bool _noImplicitTransforms;
47
49
51
53
55
56 internal string SourceName { get; set; }
57
58 internal string ActivityName { get; set; }
59
60 internal ActivityEvents Events { get; set; }
61
63
65 {
67 if (filterAndPayloadSpecs == null)
68 {
70 }
71 int num = filterAndPayloadSpecs.Length;
72 while (true)
73 {
74 if (0 < num && char.IsWhiteSpace(filterAndPayloadSpecs[num - 1]))
75 {
76 num--;
77 continue;
78 }
79 int num2 = filterAndPayloadSpecs.LastIndexOf('\n', num - 1, num);
80 int i = 0;
81 if (0 <= num2)
82 {
83 i = num2 + 1;
84 }
85 for (; i < num && char.IsWhiteSpace(filterAndPayloadSpecs[i]); i++)
86 {
87 }
89 {
91 }
92 else
93 {
94 specList = new FilterAndTransform(filterAndPayloadSpecs, i, num, eventSource, specList);
95 }
96 num = num2;
97 if (num < 0)
98 {
99 break;
100 }
101 }
102 if (eventSource._activitySourceSpecs != null)
103 {
105 CreateActivityListener(eventSource);
106 }
107 }
108
110 {
111 eventSource._activityListener?.Dispose();
112 eventSource._activityListener = null;
113 eventSource._activitySourceSpecs = null;
115 specList = null;
116 while (filterAndTransform != null)
117 {
118 filterAndTransform.Dispose();
120 }
121 }
122
124 {
126 Next = next;
127 _eventSource = eventSource;
128 string listenerNameFilter = null;
129 string eventNameFilter = null;
130 string text = null;
131 int num = startIdx;
132 int num2 = endIdx;
133 int num3 = filterAndPayloadSpec.IndexOf(':', startIdx, endIdx - startIdx);
134 if (0 <= num3)
135 {
136 num2 = num3;
137 num = num3 + 1;
138 }
139 int num4 = filterAndPayloadSpec.IndexOf('/', startIdx, num2 - startIdx);
140 if (0 <= num4)
141 {
142 listenerNameFilter = filterAndPayloadSpec.Substring(startIdx, num4 - startIdx);
143 int num5 = filterAndPayloadSpec.IndexOf('@', num4 + 1, num2 - num4 - 1);
144 if (0 <= num5)
145 {
146 text = filterAndPayloadSpec.Substring(num5 + 1, num2 - num5 - 1);
147 eventNameFilter = filterAndPayloadSpec.Substring(num4 + 1, num5 - num4 - 1);
148 }
149 else
150 {
151 eventNameFilter = filterAndPayloadSpec.Substring(num4 + 1, num2 - num4 - 1);
152 }
153 }
154 else if (startIdx < num2)
155 {
156 listenerNameFilter = filterAndPayloadSpec.Substring(startIdx, num2 - startIdx);
157 }
158 _eventSource.Message("DiagnosticSource: Enabling '" + (listenerNameFilter ?? "*") + "/" + (eventNameFilter ?? "*") + "'");
159 if (num < endIdx && filterAndPayloadSpec[num] == '-')
160 {
161 _eventSource.Message("DiagnosticSource: suppressing implicit transforms.");
163 num++;
164 }
165 if (num < endIdx)
166 {
167 while (true)
168 {
169 int num6 = num;
170 int num7 = filterAndPayloadSpec.LastIndexOf(';', endIdx - 1, endIdx - num);
171 if (0 <= num7)
172 {
173 num6 = num7 + 1;
174 }
175 if (num6 < endIdx)
176 {
177 if (_eventSource.IsEnabled(EventLevel.Informational, (EventKeywords)1L))
178 {
179 _eventSource.Message("DiagnosticSource: Parsing Explicit Transform '" + filterAndPayloadSpec.Substring(num6, endIdx - num6) + "'");
180 }
182 }
183 if (num == num6)
184 {
185 break;
186 }
187 endIdx = num7;
188 }
189 }
191 if (text != null && text.Contains("Activity"))
192 {
193 writeEvent = text switch
194 {
195 "Activity1Start" => _eventSource.Activity1Start,
196 "Activity1Stop" => _eventSource.Activity1Stop,
197 "Activity2Start" => _eventSource.Activity2Start,
198 "Activity2Stop" => _eventSource.Activity2Stop,
199 "RecursiveActivity1Start" => _eventSource.RecursiveActivity1Start,
200 "RecursiveActivity1Stop" => _eventSource.RecursiveActivity1Stop,
201 _ => null,
202 };
203 if (writeEvent == null)
204 {
205 _eventSource.Message("DiagnosticSource: Could not find Event to log Activity " + text);
206 }
207 }
208 if (writeEvent == null)
209 {
211 }
213 {
215 {
216 filterAndTransform._eventSource.NewDiagnosticListener(newListener.Name);
217 Predicate<string> isEnabled = null;
218 if (eventNameFilter != null)
219 {
220 isEnabled = (string eventName) => eventNameFilter == eventName;
221 }
223 filterAndTransform._liveSubscriptions = new Subscriptions(subscription, filterAndTransform._liveSubscriptions);
224 }
225 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "DiagnosticSource.Write is marked with RequiresUnreferencedCode.")]
226 void OnEventWritten(KeyValuePair<string, object> evnt)
227 {
228 if (eventNameFilter == null || !(eventNameFilter != evnt.Key))
229 {
231 string key = evnt.Key;
233 }
234 }
235 }));
236 }
237
239 {
240 _eventSource = eventSource;
241 Next = _eventSource._activitySourceSpecs;
242 _eventSource._activitySourceSpecs = this;
243 SourceName = activitySourceName;
244 ActivityName = activityName;
245 Events = events;
246 SamplingResult = samplingResult;
247 if (colonIdx < 0)
248 {
249 return;
250 }
251 int num = colonIdx + 1;
252 if (num < endIdx && filterAndPayloadSpec[num] == '-')
253 {
254 _eventSource.Message("DiagnosticSource: suppressing implicit transforms.");
255 _noImplicitTransforms = true;
256 num++;
257 }
258 if (num >= endIdx)
259 {
260 return;
261 }
262 while (true)
263 {
264 int num2 = num;
265 int num3 = filterAndPayloadSpec.LastIndexOf(';', endIdx - 1, endIdx - num);
266 if (0 <= num3)
267 {
268 num2 = num3 + 1;
269 }
270 if (num2 < endIdx)
271 {
272 if (_eventSource.IsEnabled(EventLevel.Informational, (EventKeywords)1L))
273 {
274 _eventSource.Message("DiagnosticSource: Parsing Explicit Transform '" + filterAndPayloadSpec.Substring(num2, endIdx - num2) + "'");
275 }
276 _explicitTransforms = new TransformSpec(filterAndPayloadSpec, num2, endIdx, _explicitTransforms);
277 }
278 if (num != num2)
279 {
280 endIdx = num3;
281 continue;
282 }
283 break;
284 }
285 }
286
287 [MethodImpl(MethodImplOptions.AggressiveInlining)]
288 internal static bool IsActivitySourceEntry(string filterAndPayloadSpec, int startIdx, int endIdx)
289 {
290 return filterAndPayloadSpec.AsSpan(startIdx, endIdx - startIdx).StartsWith("[AS]".AsSpan(), StringComparison.Ordinal);
291 }
292
293 internal static void AddNewActivitySourceTransform(string filterAndPayloadSpec, int startIdx, int endIdx, DiagnosticSourceEventSource eventSource)
294 {
295 ActivityEvents events = ActivityEvents.All;
297 int num = filterAndPayloadSpec.IndexOf(':', startIdx + "[AS]".Length, endIdx - startIdx - "[AS]".Length);
298 ReadOnlySpan<char> readOnlySpan = filterAndPayloadSpec.AsSpan(startIdx + "[AS]".Length, ((num >= 0) ? num : endIdx) - startIdx - "[AS]".Length).Trim();
299 int num2 = readOnlySpan.IndexOf('/');
301 if (num2 >= 0)
302 {
303 span = readOnlySpan.Slice(0, num2).Trim();
304 ReadOnlySpan<char> readOnlySpan2 = readOnlySpan.Slice(num2 + 1, readOnlySpan.Length - num2 - 1).Trim();
305 int num3 = readOnlySpan2.IndexOf('-');
307 if (num3 >= 0)
308 {
309 span2 = readOnlySpan2.Slice(0, num3).Trim();
310 readOnlySpan2 = readOnlySpan2.Slice(num3 + 1, readOnlySpan2.Length - num3 - 1).Trim();
311 if (readOnlySpan2.Length > 0)
312 {
313 if (MemoryExtensions.Equals(readOnlySpan2, "Propagate".AsSpan(), StringComparison.OrdinalIgnoreCase))
314 {
315 samplingResult = ActivitySamplingResult.PropagationData;
316 }
317 else
318 {
319 if (!MemoryExtensions.Equals(readOnlySpan2, "Record".AsSpan(), StringComparison.OrdinalIgnoreCase))
320 {
321 return;
322 }
324 }
325 }
326 }
327 else
328 {
330 }
331 if (span2.Length > 0)
332 {
333 if (MemoryExtensions.Equals(span2, "Start".AsSpan(), StringComparison.OrdinalIgnoreCase))
334 {
335 events = ActivityEvents.ActivityStart;
336 }
337 else
338 {
339 if (!MemoryExtensions.Equals(span2, "Stop".AsSpan(), StringComparison.OrdinalIgnoreCase))
340 {
341 return;
342 }
343 events = ActivityEvents.ActivityStop;
344 }
345 }
346 }
347 else
348 {
350 }
351 string activityName = null;
352 int num4 = span.IndexOf('+');
353 if (num4 >= 0)
354 {
355 activityName = span.Slice(num4 + 1).Trim().ToString();
356 span = span.Slice(0, num4).Trim();
357 }
359 }
360
362 {
366 while (filterAndTransform != null)
367 {
368 if (filterAndTransform.ActivityName == null || filterAndTransform.ActivityName == activityName)
369 {
370 if (activitySourceName == filterAndTransform.SourceName)
371 {
372 if (filterAndTransform.SamplingResult > activitySamplingResult)
373 {
375 }
376 if (activitySamplingResult >= ActivitySamplingResult.AllDataAndRecorded)
377 {
379 }
380 }
381 else if (filterAndTransform.SourceName == "*")
382 {
383 if (activitySamplingResult != 0)
384 {
386 }
387 if (filterAndTransform.SamplingResult > activitySamplingResult2)
388 {
390 }
391 }
392 }
394 }
396 {
398 }
400 }
401
402 internal static void CreateActivityListener(DiagnosticSourceEventSource eventSource)
403 {
404 eventSource._activityListener = new ActivityListener();
405 eventSource._activityListener.SampleUsingParentId = delegate(ref ActivityCreationOptions<string> activityOptions)
406 {
407 return Sample(activityOptions.Source.Name, activityOptions.Name, eventSource);
408 };
409 eventSource._activityListener.Sample = delegate(ref ActivityCreationOptions<ActivityContext> activityOptions)
410 {
411 return Sample(activityOptions.Source.Name, activityOptions.Name, eventSource);
412 };
413 eventSource._activityListener.ShouldListenTo = delegate(ActivitySource activitySource)
414 {
416 {
417 if (activitySource.Name == filterAndTransform.SourceName || filterAndTransform.SourceName == "*")
418 {
419 return true;
420 }
421 }
422 return false;
423 };
424 eventSource._activityListener.ActivityStarted = delegate(Activity activity)
425 {
426 OnActivityStarted(eventSource, activity);
427 };
428 eventSource._activityListener.ActivityStopped = delegate(Activity activity)
429 {
430 OnActivityStopped(eventSource, activity);
431 };
433 }
434
441 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Activity's properties are being preserved with the DynamicDependencies on OnActivityStarted.")]
443 {
445 {
446 if ((filterAndTransform.Events & ActivityEvents.ActivityStart) != 0 && (activity.Source.Name == filterAndTransform.SourceName || filterAndTransform.SourceName == "*") && (filterAndTransform.ActivityName == null || filterAndTransform.ActivityName == activity.OperationName))
447 {
448 eventSource.ActivityStart(activity.Source.Name, activity.OperationName, filterAndTransform.Morph(activity));
449 break;
450 }
451 }
452 }
453
454 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Activity's properties are being preserved with the DynamicDependencies on OnActivityStarted.")]
456 {
458 {
459 if ((filterAndTransform.Events & ActivityEvents.ActivityStop) != 0 && (activity.Source.Name == filterAndTransform.SourceName || filterAndTransform.SourceName == "*") && (filterAndTransform.ActivityName == null || filterAndTransform.ActivityName == activity.OperationName))
460 {
461 eventSource.ActivityStop(activity.Source.Name, activity.OperationName, filterAndTransform.Morph(activity));
462 break;
463 }
464 }
465 }
466
468 {
474 while (filterAndTransform != null)
475 {
476 if (filterAndTransform.SourceName == "*")
477 {
478 if (filterAndTransform4 == null)
479 {
481 }
482 else
483 {
484 filterAndTransform5.Next = filterAndTransform;
486 }
487 }
488 else if (filterAndTransform2 == null)
489 {
491 }
492 else
493 {
494 filterAndTransform3.Next = filterAndTransform;
496 }
498 }
499 if (filterAndTransform2 != null && filterAndTransform4 != null)
500 {
501 filterAndTransform3.Next = filterAndTransform4;
502 filterAndTransform5.Next = null;
503 eventSource._activitySourceSpecs = filterAndTransform2;
504 }
505 }
506
507 private void Dispose()
508 {
509 if (_diagnosticsListenersSubscription != null)
510 {
511 _diagnosticsListenersSubscription.Dispose();
512 _diagnosticsListenersSubscription = null;
513 }
514 if (_liveSubscriptions != null)
515 {
516 Subscriptions subscriptions = _liveSubscriptions;
517 _liveSubscriptions = null;
518 while (subscriptions != null)
519 {
520 subscriptions.Subscription.Dispose();
522 }
523 }
524 }
525
526 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
527 [RequiresUnreferencedCode("The type of object being written to DiagnosticSource cannot be discovered statically.")]
529 {
531 if (args != null)
532 {
533 if (!_noImplicitTransforms)
534 {
535 Type type2 = args.GetType();
536 ImplicitTransformEntry firstImplicitTransformsEntry = _firstImplicitTransformsEntry;
539 {
541 }
542 else if (firstImplicitTransformsEntry == null)
543 {
544 transformSpec = MakeImplicitTransforms(type2);
545 Interlocked.CompareExchange(ref _firstImplicitTransformsEntry, new ImplicitTransformEntry
546 {
547 Type = type2,
548 Transforms = transformSpec
549 }, null);
550 }
551 else
552 {
553 if (_implicitTransformsTable == null)
554 {
555 Interlocked.CompareExchange(ref _implicitTransformsTable, new ConcurrentDictionary<Type, TransformSpec>(1, 8), null);
556 }
557 transformSpec = _implicitTransformsTable.GetOrAdd(type2, (Type type) => MakeImplicitTransformsWrapper(type));
558 }
559 if (transformSpec != null)
560 {
562 {
563 list.Add(transformSpec2.Morph(args));
564 }
565 }
566 }
567 if (_explicitTransforms != null)
568 {
569 for (TransformSpec transformSpec3 = _explicitTransforms; transformSpec3 != null; transformSpec3 = transformSpec3.Next)
570 {
572 if (item.Value != null)
573 {
574 list.Add(item);
575 }
576 }
577 }
578 }
579 return list;
580 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The Morph method has RequiresUnreferencedCode, but the trimmer can't see through lamdba calls.")]
582 {
583 return MakeImplicitTransforms(transformType);
584 }
585 }
586
587 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
588 [RequiresUnreferencedCode("The type of object being written to DiagnosticSource cannot be discovered statically.")]
590 {
592 TypeInfo typeInfo = type.GetTypeInfo();
593 PropertyInfo[] properties = typeInfo.GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
594 foreach (PropertyInfo propertyInfo in properties)
595 {
596 if (!(propertyInfo.GetMethod == null) && propertyInfo.GetMethod.GetParameters().Length == 0)
597 {
598 transformSpec = new TransformSpec(propertyInfo.Name, 0, propertyInfo.Name.Length, transformSpec);
599 }
600 }
601 return Reverse(transformSpec);
602 }
603
605 {
607 while (list != null)
608 {
609 TransformSpec next = list.Next;
610 list.Next = transformSpec;
612 list = next;
613 }
614 return transformSpec;
615 }
616 }
617
618 internal sealed class ImplicitTransformEntry
619 {
620 public Type Type;
621
623 }
624
625 internal sealed class TransformSpec
626 {
627 internal sealed class PropertySpec
628 {
629 private class PropertyFetch
630 {
632 {
634
636 : base(type)
637 {
638 _propertyFetch = (Func<TObject, TProperty>)property.GetMethod.CreateDelegate(typeof(Func<TObject, TProperty>));
639 }
640
641 public override object Fetch(object obj)
642 {
643 return _propertyFetch((TObject)obj);
644 }
645 }
646
648
650 {
652
654 : base(type)
655 {
656 _propertyFetch = (StructFunc<TStruct, TProperty>)property.GetMethod.CreateDelegate(typeof(StructFunc<TStruct, TProperty>));
657 }
658
659 public override object Fetch(object obj)
660 {
662 return _propertyFetch(ref thisArg);
663 }
664 }
665
667 {
669 : base(null)
670 {
671 }
672
673 public override object Fetch(object obj)
674 {
675 return Activity.Current;
676 }
677 }
678
679 private sealed class EnumeratePropertyFetch<ElementType> : PropertyFetch
680 {
682 : base(type)
683 {
684 }
685
686 public override object Fetch(object obj)
687 {
688 return string.Join(",", (IEnumerable<ElementType>)obj);
689 }
690 }
691
692 internal Type Type { get; }
693
694 public PropertyFetch(Type type)
695 {
696 Type = type;
697 }
698
699 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
700 [RequiresUnreferencedCode("The type of object being written to DiagnosticSource cannot be discovered statically.")]
702 {
703 if (propertyName == null)
704 {
705 return new PropertyFetch(type);
706 }
707 if (propertyName == "*Activity")
708 {
709 return new CurrentActivityPropertyFetch();
710 }
711 TypeInfo typeInfo = type.GetTypeInfo();
712 if (propertyName == "*Enumerate")
713 {
714 Type[] interfaces = typeInfo.GetInterfaces();
715 foreach (Type type2 in interfaces)
716 {
717 TypeInfo typeInfo2 = type2.GetTypeInfo();
718 if (typeInfo2.IsGenericType && !(typeInfo2.GetGenericTypeDefinition() != typeof(IEnumerable<>)))
719 {
720 Type type3 = typeInfo2.GetGenericArguments()[0];
721 Type type4 = typeof(EnumeratePropertyFetch<>).GetTypeInfo().MakeGenericType(type3);
723 }
724 }
725 Log.Message($"*Enumerate applied to non-enumerable type {type}");
726 return new PropertyFetch(type);
727 }
728 PropertyInfo propertyInfo = typeInfo.GetDeclaredProperty(propertyName);
729 if (propertyInfo == null)
730 {
731 PropertyInfo[] properties = typeInfo.GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
732 foreach (PropertyInfo propertyInfo2 in properties)
733 {
734 if (propertyInfo2.Name == propertyName)
735 {
736 propertyInfo = propertyInfo2;
737 break;
738 }
739 }
740 }
741 if (propertyInfo == null)
742 {
743 Log.Message($"Property {propertyName} not found on {type}. Ensure the name is spelled correctly. If you published the application with PublishTrimmed=true, ensure the property was not trimmed away.");
744 return new PropertyFetch(type);
745 }
746 MethodInfo? getMethod = propertyInfo.GetMethod;
747 if ((object)getMethod == null || !getMethod.IsStatic)
748 {
749 MethodInfo? setMethod = propertyInfo.SetMethod;
750 if ((object)setMethod == null || !setMethod.IsStatic)
751 {
753 Type type6 = type5.GetTypeInfo().MakeGenericType(propertyInfo.DeclaringType, propertyInfo.PropertyType);
754 return (PropertyFetch)Activator.CreateInstance(type6, type, propertyInfo);
755 }
756 }
757 Log.Message("Property " + propertyName + " is static.");
758 return new PropertyFetch(type);
759 }
760
761 public virtual object Fetch(object obj)
762 {
763 return null;
764 }
765 }
766
768
769 private readonly string _propertyName;
770
772
773 public bool IsStatic { get; private set; }
774
776 {
777 Next = next;
778 _propertyName = propertyName;
779 if (_propertyName == "*Activity")
780 {
781 IsStatic = true;
782 }
783 }
784
785 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
786 [RequiresUnreferencedCode("The type of object being written to DiagnosticSource cannot be discovered statically.")]
787 public object Fetch(object obj)
788 {
789 PropertyFetch propertyFetch = _fetchForExpectedType;
790 Type type = obj?.GetType();
791 if (propertyFetch == null || propertyFetch.Type != type)
792 {
793 propertyFetch = (_fetchForExpectedType = PropertyFetch.FetcherForProperty(type, _propertyName));
794 }
795 object result = null;
796 try
797 {
798 result = propertyFetch.Fetch(obj);
799 }
800 catch (Exception value)
801 {
802 Log.Message($"Property {type}.{_propertyName} threw the exception {value}");
803 }
804 return result;
805 }
806 }
807
809
810 private readonly string _outputName;
811
812 private readonly PropertySpec _fetches;
813
814 public TransformSpec(string transformSpec, int startIdx, int endIdx, TransformSpec next = null)
815 {
816 Next = next;
817 int num = transformSpec.IndexOf('=', startIdx, endIdx - startIdx);
818 if (0 <= num)
819 {
820 _outputName = transformSpec.Substring(startIdx, num - startIdx);
821 startIdx = num + 1;
822 }
823 while (startIdx < endIdx)
824 {
825 int num2 = transformSpec.LastIndexOf('.', endIdx - 1, endIdx - startIdx);
826 int num3 = startIdx;
827 if (0 <= num2)
828 {
829 num3 = num2 + 1;
830 }
831 string text = transformSpec.Substring(num3, endIdx - num3);
832 _fetches = new PropertySpec(text, _fetches);
833 if (_outputName == null)
834 {
835 _outputName = text;
836 }
837 endIdx = num2;
838 }
839 }
840
841 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode", Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
842 [RequiresUnreferencedCode("The type of object being written to DiagnosticSource cannot be discovered statically.")]
844 {
845 for (PropertySpec propertySpec = _fetches; propertySpec != null; propertySpec = propertySpec.Next)
846 {
847 if (obj != null || propertySpec.IsStatic)
848 {
849 obj = propertySpec.Fetch(obj);
850 }
851 }
852 return new KeyValuePair<string, string>(_outputName, obj?.ToString());
853 }
854 }
855
856 internal sealed class CallbackObserver<T> : IObserver<T>
857 {
858 private readonly Action<T> _callback;
859
861 {
862 _callback = callback;
863 }
864
865 public void OnCompleted()
866 {
867 }
868
870 {
871 }
872
873 public void OnNext(T value)
874 {
875 _callback(value);
876 }
877 }
878
879 internal sealed class Subscriptions
880 {
882
884
886 {
887 Subscription = subscription;
888 Next = next;
889 }
890 }
891
893
894 private readonly string AspNetCoreHostingKeywordValue = "Microsoft.AspNetCore/Microsoft.AspNetCore.Hosting.BeginRequest@Activity1Start:-httpContext.Request.Method;httpContext.Request.Host;httpContext.Request.Path;httpContext.Request.QueryString\nMicrosoft.AspNetCore/Microsoft.AspNetCore.Hosting.EndRequest@Activity1Stop:-httpContext.TraceIdentifier;httpContext.Response.StatusCode";
895
896 private readonly string EntityFrameworkCoreCommandsKeywordValue = "Microsoft.EntityFrameworkCore/Microsoft.EntityFrameworkCore.BeforeExecuteCommand@Activity2Start:-Command.Connection.DataSource;Command.Connection.Database;Command.CommandText\nMicrosoft.EntityFrameworkCore/Microsoft.EntityFrameworkCore.AfterExecuteCommand@Activity2Stop:-";
897
898 private volatile bool _false;
899
901
903
905
906 [Event(1, Keywords = (EventKeywords)1L)]
907 public void Message(string Message)
908 {
909 WriteEvent(1, Message);
910 }
911
912 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Arguments parameter is trimmer safe")]
913 [Event(2, Keywords = (EventKeywords)2L)]
914 private void Event(string SourceName, string EventName, IEnumerable<KeyValuePair<string, string>> Arguments)
915 {
916 WriteEvent(2, SourceName, EventName, Arguments);
917 }
918
919 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Arguments parameter is trimmer safe")]
920 [Event(4, Keywords = (EventKeywords)2L)]
921 private void Activity1Start(string SourceName, string EventName, IEnumerable<KeyValuePair<string, string>> Arguments)
922 {
923 WriteEvent(4, SourceName, EventName, Arguments);
924 }
925
926 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Arguments parameter is trimmer safe")]
927 [Event(5, Keywords = (EventKeywords)2L)]
928 private void Activity1Stop(string SourceName, string EventName, IEnumerable<KeyValuePair<string, string>> Arguments)
929 {
930 WriteEvent(5, SourceName, EventName, Arguments);
931 }
932
933 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Arguments parameter is trimmer safe")]
934 [Event(6, Keywords = (EventKeywords)2L)]
935 private void Activity2Start(string SourceName, string EventName, IEnumerable<KeyValuePair<string, string>> Arguments)
936 {
937 WriteEvent(6, SourceName, EventName, Arguments);
938 }
939
940 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Arguments parameter is trimmer safe")]
941 [Event(7, Keywords = (EventKeywords)2L)]
942 private void Activity2Stop(string SourceName, string EventName, IEnumerable<KeyValuePair<string, string>> Arguments)
943 {
944 WriteEvent(7, SourceName, EventName, Arguments);
945 }
946
947 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Arguments parameter is trimmer safe")]
948 [Event(8, Keywords = (EventKeywords)2L, ActivityOptions = EventActivityOptions.Recursive)]
949 private void RecursiveActivity1Start(string SourceName, string EventName, IEnumerable<KeyValuePair<string, string>> Arguments)
950 {
951 WriteEvent(8, SourceName, EventName, Arguments);
952 }
953
954 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Arguments parameter is trimmer safe")]
955 [Event(9, Keywords = (EventKeywords)2L, ActivityOptions = EventActivityOptions.Recursive)]
956 private void RecursiveActivity1Stop(string SourceName, string EventName, IEnumerable<KeyValuePair<string, string>> Arguments)
957 {
958 WriteEvent(9, SourceName, EventName, Arguments);
959 }
960
961 [Event(10, Keywords = (EventKeywords)2L)]
962 private void NewDiagnosticListener(string SourceName)
963 {
964 WriteEvent(10, SourceName);
965 }
966
967 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Arguments parameter is trimmer safe")]
968 [Event(11, Keywords = (EventKeywords)2L, ActivityOptions = EventActivityOptions.Recursive)]
969 private void ActivityStart(string SourceName, string ActivityName, IEnumerable<KeyValuePair<string, string>> Arguments)
970 {
971 WriteEvent(11, SourceName, ActivityName, Arguments);
972 }
973
974 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Arguments parameter is trimmer safe")]
975 [Event(12, Keywords = (EventKeywords)2L, ActivityOptions = EventActivityOptions.Recursive)]
976 private void ActivityStop(string SourceName, string ActivityName, IEnumerable<KeyValuePair<string, string>> Arguments)
977 {
978 WriteEvent(12, SourceName, ActivityName, Arguments);
979 }
980
985
986 [NonEvent]
988 {
989 BreakPointWithDebuggerFuncEval();
990 lock (this)
991 {
992 if ((command.Command == EventCommand.Update || command.Command == EventCommand.Enable) && IsEnabled(EventLevel.Informational, (EventKeywords)2L))
993 {
994 string value = null;
995 command.Arguments.TryGetValue("FilterAndPayloadSpecs", out value);
996 if (!IsEnabled(EventLevel.Informational, (EventKeywords)2048L))
997 {
998 if (IsEnabled(EventLevel.Informational, (EventKeywords)4096L))
999 {
1000 value = NewLineSeparate(value, AspNetCoreHostingKeywordValue);
1001 }
1002 if (IsEnabled(EventLevel.Informational, (EventKeywords)8192L))
1003 {
1004 value = NewLineSeparate(value, EntityFrameworkCoreCommandsKeywordValue);
1005 }
1006 }
1008 }
1009 else if (command.Command == EventCommand.Update || command.Command == EventCommand.Disable)
1010 {
1012 }
1013 }
1014 }
1015
1016 private static string NewLineSeparate(string str1, string str2)
1017 {
1018 if (string.IsNullOrEmpty(str1))
1019 {
1020 return str2;
1021 }
1022 return str1 + "\n" + str2;
1023 }
1024
1025 [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
1026 [NonEvent]
1028 {
1029 new object();
1030 while (_false)
1031 {
1032 _false = false;
1033 }
1034 }
1035}
static ? object CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture)
Definition Activator.cs:17
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void Add(TKey key, TValue value)
static void AddActivityListener(ActivityListener listener)
static ? Activity Current
Definition Activity.cs:662
static IObservable< DiagnosticListener > AllListeners
static bool IsActivitySourceEntry(string filterAndPayloadSpec, int startIdx, int endIdx)
static void NormalizeActivitySourceSpecsList(DiagnosticSourceEventSource eventSource)
static void OnActivityStopped(DiagnosticSourceEventSource eventSource, Activity activity)
static void OnActivityStarted(DiagnosticSourceEventSource eventSource, Activity activity)
static void CreateFilterAndTransformList(ref FilterAndTransform specList, string filterAndPayloadSpecs, DiagnosticSourceEventSource eventSource)
static void AddNewActivitySourceTransform(string filterAndPayloadSpec, int startIdx, int endIdx, DiagnosticSourceEventSource eventSource)
FilterAndTransform(string filterAndPayloadSpec, int startIdx, int endIdx, DiagnosticSourceEventSource eventSource, FilterAndTransform next)
static void DestroyFilterAndTransformList(ref FilterAndTransform specList, DiagnosticSourceEventSource eventSource)
static void CreateActivityListener(DiagnosticSourceEventSource eventSource)
FilterAndTransform(string filterAndPayloadSpec, int endIdx, int colonIdx, string activitySourceName, string activityName, ActivityEvents events, ActivitySamplingResult samplingResult, DiagnosticSourceEventSource eventSource)
static ActivitySamplingResult Sample(string activitySourceName, string activityName, DiagnosticSourceEventSource eventSource)
TransformSpec(string transformSpec, int startIdx, int endIdx, TransformSpec next=null)
void RecursiveActivity1Start(string SourceName, string EventName, IEnumerable< KeyValuePair< string, string > > Arguments)
void ActivityStart(string SourceName, string ActivityName, IEnumerable< KeyValuePair< string, string > > Arguments)
void RecursiveActivity1Stop(string SourceName, string EventName, IEnumerable< KeyValuePair< string, string > > Arguments)
void Activity2Stop(string SourceName, string EventName, IEnumerable< KeyValuePair< string, string > > Arguments)
void Activity2Start(string SourceName, string EventName, IEnumerable< KeyValuePair< string, string > > Arguments)
void Activity1Start(string SourceName, string EventName, IEnumerable< KeyValuePair< string, string > > Arguments)
void Event(string SourceName, string EventName, IEnumerable< KeyValuePair< string, string > > Arguments)
void ActivityStop(string SourceName, string ActivityName, IEnumerable< KeyValuePair< string, string > > Arguments)
override void OnEventCommand(EventCommandEventArgs command)
static string NewLineSeparate(string str1, string str2)
void Activity1Stop(string SourceName, string EventName, IEnumerable< KeyValuePair< string, string > > Arguments)
static bool Equals(this ReadOnlySpan< char > span, ReadOnlySpan< char > other, StringComparison comparisonType)
virtual ? MethodInfo GetMethod
virtual ? MethodInfo SetMethod
TypeInfo IReflectableType. GetTypeInfo()
Definition TypeInfo.cs:101
virtual ? PropertyInfo GetDeclaredProperty(string name)
Definition TypeInfo.cs:136
static int CompareExchange(ref int location1, int value, int comparand)
PropertyInfo[] GetProperties()
Definition Type.cs:877
Type[] GetInterfaces()