1 using Microsoft.Reflection;
20 [__DynamicallyInvokable]
24 [__DynamicallyInvokable]
31 internal int m_Reserved;
35 [__DynamicallyInvokable]
50 [__DynamicallyInvokable]
53 [__DynamicallyInvokable]
58 [__DynamicallyInvokable]
66 internal unsafe
void SetMetadata(
byte* pointer,
int size,
int reserved)
68 m_Ptr = (long)(ulong)(
UIntPtr)(
void*)pointer;
70 m_Reserved = reserved;
74 private struct Sha1ForNonSecretPurposes
97 public void Append(
byte input)
99 w[pos / 4] = ((w[pos / 4] << 8) | input);
106 public void Append(
byte[] input)
108 foreach (
byte input2
in input)
114 public void Finish(
byte[] output)
116 long num = length + 8 * pos;
122 Append((
byte)(num >> 56));
123 Append((
byte)(num >> 48));
124 Append((
byte)(num >> 40));
125 Append((
byte)(num >> 32));
126 Append((
byte)(num >> 24));
127 Append((
byte)(num >> 16));
130 int num2 = (output.Length < 20) ? output.Length : 20;
131 for (
int i = 0; i != num2; i++)
133 uint num3 = w[80 + i / 4];
134 output[i] = (byte)(num3 >> 24);
135 w[80 + i / 4] = num3 << 8;
141 for (
int i = 16; i != 80; i++)
143 w[i] = Rol1(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16]);
150 for (
int j = 0; j != 20; j++)
152 uint num6 = (num2 & num3) | (~num2 & num4);
153 uint num7 = Rol5(num) + num6 + num5 + 1518500249 + w[j];
160 for (
int k = 20; k != 40; k++)
162 uint num8 = num2 ^ num3 ^ num4;
163 uint num9 = Rol5(num) + num8 + num5 + 1859775393 + w[k];
170 for (
int l = 40; l != 60; l++)
172 uint num10 = (num2 & num3) | (num2 & num4) | (num3 & num4);
173 uint num11 = (uint)((
int)(Rol5(num) + num10 + num5) + -1894007588 + (
int)w[l]);
180 for (
int m = 60; m != 80; m++)
182 uint num12 = num2 ^ num3 ^ num4;
183 uint num13 = (uint)((
int)(Rol5(num) + num12 + num5) + -899497514 + (
int)w[m]);
199 private static uint Rol1(uint input)
201 return (input << 1) | (input >> 31);
204 private static uint Rol5(uint input)
206 return (input << 5) | (input >> 27);
209 private static uint Rol30(uint input)
211 return (input << 30) | (input >> 2);
215 private class OverideEventProvider : EventProvider
219 public OverideEventProvider(
EventSource eventSource)
221 m_eventSource = eventSource;
224 protected override void OnControllerCommand(ControllerCommand command,
IDictionary<string, string> arguments,
int perEventSourceSessionId,
int etwSessionId)
226 EventListener listener =
null;
227 m_eventSource.SendCommand(listener, perEventSourceSessionId, etwSessionId, (
EventCommand)command,
IsEnabled(), base.Level, base.MatchAnyKeyword, arguments);
231 internal struct EventMetadata
233 public EventDescriptor Descriptor;
237 public bool EnabledForAnyListener;
239 public bool EnabledForETW;
241 public bool HasRelatedActivityID;
243 public byte TriggersActivityTracking;
251 public TraceLoggingEventTypes TraceLoggingEventTypes;
256 private string m_name;
262 internal volatile EventMetadata[] m_eventData;
264 private volatile byte[] m_rawManifest;
266 private EventHandler<EventCommandEventArgs> m_eventCommandExecuted;
270 private bool m_eventSourceEnabled;
276 internal volatile EventDispatcher m_Dispatchers;
278 private volatile OverideEventProvider m_provider;
280 private bool m_completelyInited;
282 private Exception m_constructionException;
284 private byte m_outOfBandMessageCount;
286 private EventCommandEventArgs m_deferredCommands;
288 private string[] m_traits;
290 internal static uint s_currentPid;
293 private static byte m_EventSourceExceptionRecurenceCount = 0;
295 internal volatile ulong[] m_channelData;
297 private SessionMask m_curLiveSessions;
299 private EtwSession[] m_etwSessionIdMap;
303 internal long m_keywordTriggers;
305 internal SessionMask m_activityFilteringForETWEnabled;
307 internal static Action<Guid> s_activityDying;
309 private ActivityTracker m_activityTracker;
311 internal const string s_ActivityStartSuffix =
"Start";
313 internal const string s_ActivityStopSuffix =
"Stop";
315 private static readonly
byte[] namespaceBytes =
new byte[16]
335 private static readonly
Guid AspNetEventSourceGuid =
new Guid(
"ee799f41-cfa5-550b-bf2c-344747c1c668");
337 private byte[] providerMetadata;
341 [__DynamicallyInvokable]
344 [__DynamicallyInvokable]
353 [__DynamicallyInvokable]
356 [__DynamicallyInvokable]
365 [__DynamicallyInvokable]
368 [__DynamicallyInvokable]
377 [__DynamicallyInvokable]
380 [SecuritySafeCritical]
381 [__DynamicallyInvokable]
385 UnsafeNativeMethods.ManifestEtw.EventActivityIdControl(UnsafeNativeMethods.ManifestEtw.ActivityControl.EVENT_ACTIVITY_CTRL_GET_ID, ref ActivityId);
390 internal static Guid InternalCurrentThreadActivityId
398 guid = FallbackActivityId;
404 internal static Guid FallbackActivityId
409 return new Guid((uint)AppDomain.GetCurrentThreadId(), (ushort)s_currentPid, (ushort)(s_currentPid >> 16), 148, 27, 135, 213, 166, 92, 54, 100);
415 [__DynamicallyInvokable]
418 [__DynamicallyInvokable]
421 return m_constructionException;
425 private bool IsDisposed
429 if (m_provider !=
null)
431 return m_provider.m_disposed;
437 private bool ThrowOnEventWriteErrors
456 private bool SelfDescribingEvents
482 m_eventCommandExecuted = (EventHandler<EventCommandEventArgs>)
Delegate.
Combine(m_eventCommandExecuted, value);
483 for (
EventCommandEventArgs eventCommandEventArgs = m_deferredCommands; eventCommandEventArgs !=
null; eventCommandEventArgs = eventCommandEventArgs.nextCommand)
485 value(
this, eventCommandEventArgs);
490 m_eventCommandExecuted = (EventHandler<EventCommandEventArgs>)
Delegate.
Remove(m_eventCommandExecuted, value);
497 [__DynamicallyInvokable]
500 return m_eventSourceEnabled;
508 [__DynamicallyInvokable]
520 [__DynamicallyInvokable]
523 if (!m_eventSourceEnabled)
527 if (!IsEnabledCommon(m_eventSourceEnabled, m_level, m_matchAnyKeyword, level, keywords, channel))
537 [__DynamicallyInvokable]
540 if (eventSourceType ==
null)
545 string name = eventSourceType.
Name;
546 if (eventSourceAttribute !=
null)
548 if (eventSourceAttribute.
Guid !=
null)
556 if (eventSourceAttribute.
Name !=
null)
558 name = eventSourceAttribute.
Name;
565 return GenerateGuidFromName(name.ToUpperInvariant());
571 [__DynamicallyInvokable]
581 [__DynamicallyInvokable]
592 [__DynamicallyInvokable]
595 if (eventSourceType ==
null)
599 byte[] array = CreateManifestAndDescriptors(eventSourceType, assemblyPathToIncludeInManifest,
null, flags);
609 [__DynamicallyInvokable]
618 if (eventSource !=
null && !eventSource.IsDisposed)
620 list.Add(eventSource);
631 [__DynamicallyInvokable]
634 if (eventSource ==
null)
647 [SecuritySafeCritical]
648 [__DynamicallyInvokable]
652 if (UnsafeNativeMethods.ManifestEtw.EventActivityIdControl(UnsafeNativeMethods.ManifestEtw.ActivityControl.EVENT_ACTIVITY_CTRL_GET_SET_ID, ref activityId) == 0)
654 Action<Guid> action = s_activityDying;
655 if (action !=
null && a != activityId)
659 activityId = FallbackActivityId;
664 if (TplEtwProvider.Log !=
null)
666 TplEtwProvider.Log.SetActivityId(activityId);
673 [SecuritySafeCritical]
674 [__DynamicallyInvokable]
677 oldActivityThatWillContinue = activityId;
678 UnsafeNativeMethods.ManifestEtw.EventActivityIdControl(UnsafeNativeMethods.ManifestEtw.ActivityControl.EVENT_ACTIVITY_CTRL_GET_SET_ID, ref oldActivityThatWillContinue);
679 if (TplEtwProvider.Log !=
null)
681 TplEtwProvider.Log.SetActivityId(activityId);
688 [__DynamicallyInvokable]
691 if (m_traits !=
null)
693 for (
int i = 0; i < m_traits.Length - 1; i += 2)
695 if (m_traits[i] == key)
697 return m_traits[i + 1];
706 [__DynamicallyInvokable]
713 [__DynamicallyInvokable]
722 [__DynamicallyInvokable]
730 [__DynamicallyInvokable]
732 : this(settings, (string[])null)
741 [__DynamicallyInvokable]
744 m_config = ValidateSettings(settings);
745 Type type = GetType();
751 [__DynamicallyInvokable]
758 [SecuritySafeCritical]
759 [__DynamicallyInvokable]
769 [SecuritySafeCritical]
770 [__DynamicallyInvokable]
773 if (m_eventSourceEnabled)
786 [SecuritySafeCritical]
787 [__DynamicallyInvokable]
788 protected unsafe
void WriteEvent(
int eventId,
int arg1,
int arg2)
790 if (m_eventSourceEnabled)
806 [SecuritySafeCritical]
807 [__DynamicallyInvokable]
808 protected unsafe
void WriteEvent(
int eventId,
int arg1,
int arg2,
int arg3)
810 if (m_eventSourceEnabled)
826 [SecuritySafeCritical]
827 [__DynamicallyInvokable]
830 if (m_eventSourceEnabled)
843 [SecuritySafeCritical]
844 [__DynamicallyInvokable]
845 protected unsafe
void WriteEvent(
int eventId,
long arg1,
long arg2)
847 if (m_eventSourceEnabled)
863 [SecuritySafeCritical]
864 [__DynamicallyInvokable]
865 protected unsafe
void WriteEvent(
int eventId,
long arg1,
long arg2,
long arg3)
867 if (m_eventSourceEnabled)
883 [SecuritySafeCritical]
884 [__DynamicallyInvokable]
887 if (m_eventSourceEnabled)
893 fixed (
char* value = arg1)
897 ptr->
Size = (arg1.Length + 1) * 2;
907 [SecuritySafeCritical]
908 [__DynamicallyInvokable]
909 protected unsafe
void WriteEvent(
int eventId,
string arg1,
string arg2)
911 if (m_eventSourceEnabled)
921 fixed (
char* value = arg1)
923 fixed (
char* value2 = arg2)
927 ptr->
Size = (arg1.Length + 1) * 2;
929 ptr[1].
Size = (arg2.Length + 1) * 2;
941 [SecuritySafeCritical]
942 [__DynamicallyInvokable]
943 protected unsafe
void WriteEvent(
int eventId,
string arg1,
string arg2,
string arg3)
945 if (m_eventSourceEnabled)
959 fixed (
char* value = arg1)
961 fixed (
char* value2 = arg2)
963 fixed (
char* value3 = arg3)
967 ptr->
Size = (arg1.Length + 1) * 2;
969 ptr[1].
Size = (arg2.Length + 1) * 2;
971 ptr[2].
Size = (arg3.Length + 1) * 2;
983 [SecuritySafeCritical]
984 [__DynamicallyInvokable]
985 protected unsafe
void WriteEvent(
int eventId,
string arg1,
int arg2)
987 if (m_eventSourceEnabled)
993 fixed (
char* value = arg1)
997 ptr->
Size = (arg1.Length + 1) * 2;
1010 [SecuritySafeCritical]
1011 [__DynamicallyInvokable]
1012 protected unsafe
void WriteEvent(
int eventId,
string arg1,
int arg2,
int arg3)
1014 if (m_eventSourceEnabled)
1020 fixed (
char* value = arg1)
1024 ptr->
Size = (arg1.Length + 1) * 2;
1038 [SecuritySafeCritical]
1039 [__DynamicallyInvokable]
1040 protected unsafe
void WriteEvent(
int eventId,
string arg1,
long arg2)
1042 if (m_eventSourceEnabled)
1048 fixed (
char* value = arg1)
1052 ptr->
Size = (arg1.Length + 1) * 2;
1064 [SecuritySafeCritical]
1065 [__DynamicallyInvokable]
1066 protected unsafe
void WriteEvent(
int eventId,
long arg1,
string arg2)
1068 if (m_eventSourceEnabled)
1074 fixed (
char* value = arg2)
1080 ptr[1].
Size = (arg2.Length + 1) * 2;
1090 [SecuritySafeCritical]
1091 [__DynamicallyInvokable]
1092 protected unsafe
void WriteEvent(
int eventId,
int arg1,
string arg2)
1094 if (m_eventSourceEnabled)
1100 fixed (
char* value = arg2)
1106 ptr[1].
Size = (arg2.Length + 1) * 2;
1115 [SecuritySafeCritical]
1116 [__DynamicallyInvokable]
1119 if (m_eventSourceEnabled)
1125 int size = arg1.Length;
1126 fixed (
byte* value = &arg1[0])
1142 [SecuritySafeCritical]
1143 [__DynamicallyInvokable]
1144 protected unsafe
void WriteEvent(
int eventId,
long arg1,
byte[] arg2)
1146 if (m_eventSourceEnabled)
1152 int size = arg2.Length;
1153 fixed (
byte* value = &arg2[0])
1172 [CLSCompliant(
false)]
1184 [CLSCompliant(
false)]
1187 if (m_eventSourceEnabled)
1191 if (relatedActivityId !=
null)
1193 ValidateEventOpcodeForTransfer(ref m_eventData[eventId], m_eventData[eventId].
Name);
1195 if (m_eventData[eventId].EnabledForETW)
1199 Guid* activityID =
null;
1207 m_activityTracker.OnStart(m_name, m_eventData[eventId].
Name, m_eventData[eventId].Descriptor.Task, ref activityId, ref relatedActivityId2, m_eventData[eventId].ActivityOptions);
1210 m_activityTracker.OnStop(m_name, m_eventData[eventId].
Name, m_eventData[eventId].Descriptor.Task, ref activityId);
1215 activityID = &activityId;
1219 relatedActivityId = &relatedActivityId2;
1222 SessionMask m = SessionMask.All;
1223 if ((ulong)m_curLiveSessions != 0
L)
1225 m = GetEtwSessionMask(eventId, relatedActivityId);
1227 if ((ulong)m != 0
L || (m_legacySessions !=
null && m_legacySessions.
Count > 0))
1229 if (!SelfDescribingEvents)
1231 if (m.IsEqualOrSupersetOf(m_curLiveSessions))
1233 if (!m_provider.WriteEvent(ref m_eventData[eventId].Descriptor, activityID, relatedActivityId, eventDataCount, (
IntPtr)(
void*)data))
1235 ThrowEventSourceException(m_eventData[eventId].
Name);
1240 long num = m_eventData[eventId].Descriptor.Keywords & (long)(~SessionMask.All.ToEventKeywords());
1241 EventDescriptor eventDescriptor =
new EventDescriptor(m_eventData[eventId].Descriptor.EventId, m_eventData[eventId].Descriptor.Version, m_eventData[eventId].Descriptor.Channel, m_eventData[eventId].Descriptor.Level, m_eventData[eventId].Descriptor.Opcode, m_eventData[eventId].Descriptor.Task, (
long)m.ToEventKeywords() | num);
1242 if (!m_provider.WriteEvent(ref eventDescriptor, activityID, relatedActivityId, eventDataCount, (
IntPtr)(
void*)data))
1244 ThrowEventSourceException(m_eventData[eventId].
Name);
1250 TraceLoggingEventTypes traceLoggingEventTypes = m_eventData[eventId].TraceLoggingEventTypes;
1251 if (traceLoggingEventTypes ==
null)
1253 traceLoggingEventTypes =
new TraceLoggingEventTypes(m_eventData[eventId].
Name,
EventTags.None, m_eventData[eventId].Parameters);
1256 long num2 = m_eventData[eventId].Descriptor.Keywords & (long)(~SessionMask.All.ToEventKeywords());
1259 eventSourceOptions.
Level = (
EventLevel)m_eventData[eventId].Descriptor.Level;
1260 eventSourceOptions.
Opcode = (
EventOpcode)m_eventData[eventId].Descriptor.Opcode;
1262 WriteMultiMerge(m_eventData[eventId].
Name, ref options, traceLoggingEventTypes, activityID, relatedActivityId, data);
1266 if (m_Dispatchers !=
null && m_eventData[eventId].EnabledForAnyListener)
1268 WriteToAllListeners(eventId, relatedActivityId, eventDataCount, data);
1277 ThrowEventSourceException(m_eventData[eventId].
Name, ex);
1285 [SecuritySafeCritical]
1286 [__DynamicallyInvokable]
1289 WriteEventVarargs(eventId,
null, args);
1296 [SecuritySafeCritical]
1297 [__DynamicallyInvokable]
1300 WriteEventVarargs(eventId, &relatedActivityId, args);
1304 [__DynamicallyInvokable]
1314 [__DynamicallyInvokable]
1319 if (m_eventSourceEnabled)
1323 SendManifest(m_rawManifest);
1328 m_eventSourceEnabled =
false;
1330 if (m_provider !=
null)
1332 m_provider.Dispose();
1336 m_eventSourceEnabled =
false;
1340 [__DynamicallyInvokable]
1346 internal void WriteStringToListener(EventListener listener,
string msg, SessionMask m)
1348 if (m_eventSourceEnabled)
1350 if (listener ==
null)
1352 WriteEventString(
EventLevel.LogAlways, (
long)m.ToEventKeywords(), msg);
1357 EventWrittenEventArgs eventWrittenEventArgs =
new EventWrittenEventArgs(
this);
1358 eventWrittenEventArgs.EventId = 0;
1360 listener.OnEventWritten(eventWrittenEventArgs);
1365 private unsafe
void WriteEventRaw(
string eventName, ref EventDescriptor eventDescriptor,
Guid* activityID,
Guid* relatedActivityID,
int dataCount, IntPtr data)
1367 if (m_provider ==
null)
1369 ThrowEventSourceException(eventName);
1371 else if (!m_provider.WriteEventRaw(ref eventDescriptor, activityID, relatedActivityID, dataCount, data))
1373 ThrowEventSourceException(eventName);
1384 m_config = ValidateSettings(settings);
1385 Initialize(eventSourceGuid, eventSourceName, traits);
1388 [SecuritySafeCritical]
1389 private unsafe
void Initialize(
Guid eventSourceGuid,
string eventSourceName,
string[] traits)
1394 if (m_traits !=
null && m_traits.Length % 2 != 0)
1396 throw new ArgumentException(Environment.GetResourceString(
"TraitEven"),
"traits");
1400 throw new ArgumentException(Environment.GetResourceString(
"EventSource_NeedGuid"));
1402 if (eventSourceName ==
null)
1404 throw new ArgumentException(Environment.GetResourceString(
"EventSource_NeedName"));
1406 m_name = eventSourceName;
1407 m_guid = eventSourceGuid;
1408 m_curLiveSessions =
new SessionMask(0u);
1409 m_etwSessionIdMap =
new EtwSession[4];
1410 m_activityTracker = ActivityTracker.Instance;
1411 InitializeProviderMetadata();
1412 OverideEventProvider overideEventProvider =
new OverideEventProvider(
this);
1413 overideEventProvider.Register(eventSourceGuid);
1414 EventListener.AddEventSource(
this);
1415 m_provider = overideEventProvider;
1416 int num = Environment.OSVersion.Version.Major * 10 + Environment.OSVersion.Version.Minor;
1417 if (
Name !=
"System.Diagnostics.Eventing.FrameworkEventSource" || num >= 62)
1421 byte[] array = providerMetadata;
1422 fixed (IntPtr* data = array)
1424 int num2 = m_provider.SetInformation(UnsafeNativeMethods.ManifestEtw.EVENT_INFO_CLASS.SetTraits, data, providerMetadata.Length);
1431 m_completelyInited =
true;
1433 catch (Exception ex)
1435 if (m_constructionException ==
null)
1437 m_constructionException = ex;
1439 ReportOutOfBandMessage(
"ERROR: Exception during construction of EventSource " +
Name +
": " + ex.Message, flush:
true);
1441 lock (EventListener.EventListenersLock)
1443 for (EventCommandEventArgs eventCommandEventArgs = m_deferredCommands; eventCommandEventArgs !=
null; eventCommandEventArgs = eventCommandEventArgs.nextCommand)
1445 DoCommand(eventCommandEventArgs);
1452 if (eventSourceType ==
null)
1454 throw new ArgumentNullException(
"eventSourceType");
1456 EventSourceAttribute eventSourceAttribute = (EventSourceAttribute)GetCustomAttributeHelper(eventSourceType, typeof(EventSourceAttribute), flags);
1457 if (eventSourceAttribute !=
null && eventSourceAttribute.Name !=
null)
1459 return eventSourceAttribute.Name;
1461 return eventSourceType.Name;
1464 private static Guid GenerateGuidFromName(
string name)
1467 Sha1ForNonSecretPurposes sha1ForNonSecretPurposes =
default(Sha1ForNonSecretPurposes);
1468 sha1ForNonSecretPurposes.Start();
1469 sha1ForNonSecretPurposes.Append(namespaceBytes);
1470 sha1ForNonSecretPurposes.Append(array);
1471 Array.Resize(ref array, 16);
1472 sha1ForNonSecretPurposes.Finish(array);
1473 array[7] = (byte)((array[7] & 0xF) | 0x50);
1474 return new Guid(array);
1478 private unsafe
object DecodeObject(
int eventId,
int parameterId, ref EventData* data)
1480 IntPtr dataPointer = data->DataPointer;
1482 Type type = m_eventData[eventId].Parameters[parameterId].ParameterType;
1485 if (type == typeof(IntPtr))
1487 return *(IntPtr*)(
void*)dataPointer;
1489 if (type == typeof(
int))
1491 return *(
int*)(
void*)dataPointer;
1493 if (type == typeof(uint))
1495 return *(uint*)(
void*)dataPointer;
1497 if (type == typeof(
long))
1499 return *(
long*)(
void*)dataPointer;
1501 if (type == typeof(ulong))
1503 return (ulong)(*(
long*)(
void*)dataPointer);
1505 if (type == typeof(
byte))
1507 return *(
byte*)(
void*)dataPointer;
1509 if (type == typeof(sbyte))
1511 return *(sbyte*)(
void*)dataPointer;
1513 if (type == typeof(
short))
1515 return *(
short*)(
void*)dataPointer;
1517 if (type == typeof(ushort))
1519 return *(ushort*)(
void*)dataPointer;
1521 if (type == typeof(
float))
1523 return *(
float*)(
void*)dataPointer;
1525 if (type == typeof(
double))
1527 return *(
double*)(
void*)dataPointer;
1529 if (type == typeof(decimal))
1531 return *(decimal*)(
void*)dataPointer;
1533 if (type == typeof(
bool))
1535 if (*(
int*)(
void*)dataPointer == 1)
1541 if (type == typeof(
Guid))
1543 return *(
Guid*)(
void*)dataPointer;
1545 if (type == typeof(
char))
1547 return (
char)(*(ushort*)(
void*)dataPointer);
1549 if (type == typeof(DateTime))
1551 long fileTime = *(
long*)(
void*)dataPointer;
1552 return DateTime.FromFileTimeUtc(fileTime);
1554 if (type == typeof(
byte[]))
1556 int num = *(
int*)(
void*)dataPointer;
1557 byte[] array =
new byte[num];
1558 dataPointer = data->DataPointer;
1560 for (
int i = 0; i < num; i++)
1562 array[i] = ((
byte*)(
void*)dataPointer)[i];
1566 if (type == typeof(
byte*))
1574 type =
Enum.GetUnderlyingType(type);
1579 private EventDispatcher GetDispatcher(EventListener listener)
1581 EventDispatcher eventDispatcher;
1582 for (eventDispatcher = m_Dispatchers; eventDispatcher !=
null; eventDispatcher = eventDispatcher.m_Next)
1584 if (eventDispatcher.m_Listener == listener)
1586 return eventDispatcher;
1589 return eventDispatcher;
1593 private unsafe
void WriteEventVarargs(
int eventId,
Guid* childActivityID,
object[] args)
1595 if (m_eventSourceEnabled)
1599 if (childActivityID !=
null)
1601 ValidateEventOpcodeForTransfer(ref m_eventData[eventId], m_eventData[eventId].
Name);
1602 if (!m_eventData[eventId].HasRelatedActivityID)
1604 throw new ArgumentException(Environment.GetResourceString(
"EventSource_NoRelatedActivityId"));
1607 LogEventArgsMismatches(m_eventData[eventId].Parameters, args);
1608 if (m_eventData[eventId].EnabledForETW)
1610 Guid* activityID =
null;
1620 m_activityTracker.OnStart(m_name, m_eventData[eventId].
Name, m_eventData[eventId].Descriptor.Task, ref activityId, ref relatedActivityId, m_eventData[eventId].ActivityOptions);
1623 m_activityTracker.OnStop(m_name, m_eventData[eventId].
Name, m_eventData[eventId].Descriptor.Task, ref activityId);
1628 activityID = &activityId;
1632 childActivityID = &relatedActivityId;
1635 SessionMask m = SessionMask.All;
1636 if ((ulong)m_curLiveSessions != 0L)
1638 m = GetEtwSessionMask(eventId, childActivityID);
1640 if ((ulong)m != 0L || (m_legacySessions !=
null && m_legacySessions.
Count > 0))
1642 if (!SelfDescribingEvents)
1644 if (m.IsEqualOrSupersetOf(m_curLiveSessions))
1646 if (!m_provider.WriteEvent(ref m_eventData[eventId].Descriptor, activityID, childActivityID, args))
1648 ThrowEventSourceException(m_eventData[eventId].
Name);
1653 long num = m_eventData[eventId].Descriptor.Keywords & (long)(~SessionMask.All.ToEventKeywords());
1654 EventDescriptor eventDescriptor =
new EventDescriptor(m_eventData[eventId].Descriptor.EventId, m_eventData[eventId].Descriptor.Version, m_eventData[eventId].Descriptor.Channel, m_eventData[eventId].Descriptor.Level, m_eventData[eventId].Descriptor.Opcode, m_eventData[eventId].Descriptor.Task, (
long)m.ToEventKeywords() | num);
1655 if (!m_provider.WriteEvent(ref eventDescriptor, activityID, childActivityID, args))
1657 ThrowEventSourceException(m_eventData[eventId].
Name);
1663 TraceLoggingEventTypes traceLoggingEventTypes = m_eventData[eventId].TraceLoggingEventTypes;
1664 if (traceLoggingEventTypes ==
null)
1666 traceLoggingEventTypes =
new TraceLoggingEventTypes(m_eventData[eventId].
Name,
EventTags.None, m_eventData[eventId].Parameters);
1669 long num2 = m_eventData[eventId].Descriptor.Keywords & (long)(~SessionMask.All.ToEventKeywords());
1670 EventSourceOptions eventSourceOptions =
default(EventSourceOptions);
1671 eventSourceOptions.Keywords = (
EventKeywords)((
long)m.ToEventKeywords() | num2);
1672 eventSourceOptions.Level = (
EventLevel)m_eventData[eventId].Descriptor.Level;
1673 eventSourceOptions.Opcode = (
EventOpcode)m_eventData[eventId].Descriptor.Opcode;
1674 EventSourceOptions options = eventSourceOptions;
1675 WriteMultiMerge(m_eventData[eventId].
Name, ref options, traceLoggingEventTypes, activityID, childActivityID, args);
1679 if (m_Dispatchers !=
null && m_eventData[eventId].EnabledForAnyListener)
1681 if (AppContextSwitches.PreserveEventListnerObjectIdentity)
1683 WriteToAllListeners(eventId, childActivityID, args);
1687 object[] args2 = SerializeEventArgs(eventId, args);
1688 WriteToAllListeners(eventId, childActivityID, args2);
1692 catch (Exception ex)
1694 if (ex is EventSourceException)
1698 ThrowEventSourceException(m_eventData[eventId].
Name, ex);
1704 private object[] SerializeEventArgs(
int eventId,
object[] args)
1706 TraceLoggingEventTypes traceLoggingEventTypes = m_eventData[eventId].TraceLoggingEventTypes;
1707 if (traceLoggingEventTypes ==
null)
1709 traceLoggingEventTypes =
new TraceLoggingEventTypes(m_eventData[eventId].
Name,
EventTags.None, m_eventData[eventId].Parameters);
1712 object[] array =
new object[traceLoggingEventTypes.typeInfos.Length];
1713 for (
int i = 0; i < traceLoggingEventTypes.typeInfos.Length; i++)
1715 array[i] = traceLoggingEventTypes.typeInfos[i].GetData(args[i]);
1720 private void LogEventArgsMismatches(
ParameterInfo[] infos,
object[] args)
1722 bool flag = args.Length == infos.Length;
1724 while (flag && num < args.Length)
1727 if ((args[num] !=
null && args[num].GetType() != parameterType) || (args[num] ==
null && (!parameterType.IsGenericType || !(parameterType.GetGenericTypeDefinition() == typeof(Nullable<>)))))
1736 Debugger.Log(0,
null, Environment.GetResourceString(
"EventSource_VarArgsParameterMismatch") +
"\r\n");
1740 private int GetParamLengthIncludingByteArray(
ParameterInfo[] parameters)
1745 num = ((!(parameterInfo.
ParameterType == typeof(
byte[]))) ? (num + 1) : (num + 2));
1751 private unsafe
void WriteToAllListeners(
int eventId,
Guid* childActivityID,
int eventDataCount, EventData* data)
1753 int num = m_eventData[eventId].Parameters.Length;
1754 int paramLengthIncludingByteArray = GetParamLengthIncludingByteArray(m_eventData[eventId].Parameters);
1755 if (eventDataCount != paramLengthIncludingByteArray)
1757 ReportOutOfBandMessage(Environment.GetResourceString(
"EventSource_EventParametersMismatch", eventId, eventDataCount, num), flush:
true);
1758 num = Math.Min(num, eventDataCount);
1760 object[] array =
new object[num];
1761 EventData* data2 = data;
1762 for (
int i = 0; i < num; i++)
1764 array[i] = DecodeObject(eventId, i, ref data2);
1766 WriteToAllListeners(eventId, childActivityID, array);
1770 private unsafe
void WriteToAllListeners(
int eventId,
Guid* childActivityID, params
object[] args)
1772 EventWrittenEventArgs eventWrittenEventArgs =
new EventWrittenEventArgs(
this);
1773 eventWrittenEventArgs.EventId = eventId;
1774 if (childActivityID !=
null)
1776 eventWrittenEventArgs.RelatedActivityId = *childActivityID;
1778 eventWrittenEventArgs.EventName = m_eventData[eventId].Name;
1779 eventWrittenEventArgs.Message = m_eventData[eventId].Message;
1781 DispatchToAllListeners(eventId, childActivityID, eventWrittenEventArgs);
1785 private unsafe
void DispatchToAllListeners(
int eventId,
Guid* childActivityID, EventWrittenEventArgs eventCallbackArgs)
1787 Exception ex =
null;
1788 for (EventDispatcher eventDispatcher = m_Dispatchers; eventDispatcher !=
null; eventDispatcher = eventDispatcher.m_Next)
1790 if (eventId == -1 || eventDispatcher.m_EventEnabled[eventId])
1792 ActivityFilter activityFilter = eventDispatcher.m_Listener.m_activityFilter;
1793 if (activityFilter ==
null || ActivityFilter.PassesActivityFilter(activityFilter, childActivityID, m_eventData[eventId].TriggersActivityTracking > 0,
this, eventId) || !eventDispatcher.m_activityFilteringEnabled)
1797 eventDispatcher.m_Listener.OnEventWritten(eventCallbackArgs);
1799 catch (Exception ex2)
1801 ReportOutOfBandMessage(
"ERROR: Exception during EventSource.OnEventWritten: " + ex2.Message, flush:
false);
1809 throw new EventSourceException(ex);
1813 [SecuritySafeCritical]
1814 private unsafe
void WriteEventString(
EventLevel level,
long keywords,
string msgString)
1816 if (m_provider ==
null)
1820 string text =
"EventSourceMessage";
1821 if (SelfDescribingEvents)
1823 EventSourceOptions eventSourceOptions =
default(EventSourceOptions);
1825 eventSourceOptions.Level = level;
1826 EventSourceOptions options = eventSourceOptions;
1831 TraceLoggingEventTypes eventTypes =
new TraceLoggingEventTypes(text,
EventTags.None, anon.GetType());
1832 WriteMultiMergeInner(text, ref options, eventTypes,
null,
null, anon);
1835 if (m_rawManifest ==
null && m_outOfBandMessageCount == 1)
1838 manifestBuilder.StartEvent(text,
new EventAttribute(0)
1843 manifestBuilder.AddEventParameter(typeof(
string),
"message");
1844 manifestBuilder.EndEvent();
1845 SendManifest(manifestBuilder.CreateManifest());
1847 fixed (
char* ptr = msgString)
1849 EventDescriptor eventDescriptor =
new EventDescriptor(0, 0, 0, (
byte)level, 0, 0, keywords);
1850 EventProvider.EventData eventData =
default(EventProvider.EventData);
1851 eventData.Ptr = (ulong)ptr;
1852 eventData.Size = (uint)(2 * (msgString.Length + 1));
1853 eventData.Reserved = 0u;
1854 m_provider.WriteEvent(ref eventDescriptor,
null,
null, 1, (IntPtr)(
void*)(&eventData));
1858 private void WriteStringToAllListeners(
string eventName,
string msg)
1860 EventWrittenEventArgs eventWrittenEventArgs =
new EventWrittenEventArgs(
this);
1861 eventWrittenEventArgs.EventId = 0;
1862 eventWrittenEventArgs.Message = msg;
1871 eventWrittenEventArgs.EventName = eventName;
1872 for (EventDispatcher eventDispatcher = m_Dispatchers; eventDispatcher !=
null; eventDispatcher = eventDispatcher.m_Next)
1875 if (eventDispatcher.m_EventEnabled ==
null)
1881 for (
int i = 0; i < eventDispatcher.m_EventEnabled.Length; i++)
1883 if (eventDispatcher.m_EventEnabled[i])
1894 eventDispatcher.m_Listener.OnEventWritten(eventWrittenEventArgs);
1904 private unsafe SessionMask GetEtwSessionMask(
int eventId,
Guid* childActivityID)
1906 SessionMask result =
default(SessionMask);
1907 for (
int i = 0; (long)i < 4L; i++)
1909 EtwSession etwSession = m_etwSessionIdMap[i];
1910 if (etwSession !=
null)
1912 ActivityFilter activityFilter = etwSession.m_activityFilter;
1913 if ((activityFilter ==
null && !m_activityFilteringForETWEnabled[i]) || (activityFilter !=
null && ActivityFilter.PassesActivityFilter(activityFilter, childActivityID, m_eventData[eventId].TriggersActivityTracking > 0,
this, eventId)) || !m_activityFilteringForETWEnabled[i])
1919 if (m_legacySessions !=
null && m_legacySessions.
Count > 0 && m_eventData[eventId].Descriptor.Opcode == 9)
1923 foreach (EtwSession legacySession
in m_legacySessions)
1925 if (legacySession !=
null)
1927 ActivityFilter activityFilter2 = legacySession.m_activityFilter;
1928 if (activityFilter2 !=
null)
1932 Guid internalCurrentThreadActivityId = InternalCurrentThreadActivityId;
1933 ptr = &internalCurrentThreadActivityId;
1935 ActivityFilter.FlowActivityIfNeeded(activityFilter2, ptr, childActivityID);
1945 private bool IsEnabledByDefault(
int eventNum,
bool enable,
EventLevel currentLevel,
EventKeywords currentMatchAnyKeyword)
1952 EventKeywords eventKeywords = (
EventKeywords)(m_eventData[eventNum].Descriptor.Keywords & (long)(~SessionMask.All.ToEventKeywords()));
1954 return IsEnabledCommon(enable, currentLevel, currentMatchAnyKeyword, level, eventKeywords, channel);
1963 if (currentLevel != 0 && currentLevel < eventLevel)
1969 if (eventChannel != 0 && m_channelData !=
null && m_channelData.Length > (
int)eventChannel)
1977 else if ((eventKeywords & currentMatchAnyKeyword) ==
EventKeywords.None)
1986 private void ThrowEventSourceException(
string eventName, Exception innerEx =
null)
1988 if (m_EventSourceExceptionRecurenceCount <= 0)
1992 m_EventSourceExceptionRecurenceCount++;
1993 string text =
"EventSourceException";
1994 if (eventName !=
null)
1996 text = text +
" while processing event \"" + eventName +
"\"";
1998 switch (EventProvider.GetLastWriteEventError())
2000 case EventProvider.WriteEventErrorCode.EventTooBig:
2001 ReportOutOfBandMessage(text +
": " + Environment.GetResourceString(
"EventSource_EventTooBig"), flush:
true);
2002 if (ThrowOnEventWriteErrors)
2004 throw new EventSourceException(Environment.GetResourceString(
"EventSource_EventTooBig"), innerEx);
2007 case EventProvider.WriteEventErrorCode.NoFreeBuffers:
2008 ReportOutOfBandMessage(text +
": " + Environment.GetResourceString(
"EventSource_NoFreeBuffers"), flush:
true);
2009 if (ThrowOnEventWriteErrors)
2011 throw new EventSourceException(Environment.GetResourceString(
"EventSource_NoFreeBuffers"), innerEx);
2014 case EventProvider.WriteEventErrorCode.NullInput:
2015 ReportOutOfBandMessage(text +
": " + Environment.GetResourceString(
"EventSource_NullInput"), flush:
true);
2016 if (ThrowOnEventWriteErrors)
2018 throw new EventSourceException(Environment.GetResourceString(
"EventSource_NullInput"), innerEx);
2021 case EventProvider.WriteEventErrorCode.TooManyArgs:
2022 ReportOutOfBandMessage(text +
": " + Environment.GetResourceString(
"EventSource_TooManyArgs"), flush:
true);
2023 if (ThrowOnEventWriteErrors)
2025 throw new EventSourceException(Environment.GetResourceString(
"EventSource_TooManyArgs"), innerEx);
2029 if (innerEx !=
null)
2031 ReportOutOfBandMessage(text +
": " + innerEx.GetType() +
":" + innerEx.Message, flush:
true);
2035 ReportOutOfBandMessage(text, flush:
true);
2037 if (ThrowOnEventWriteErrors)
2039 throw new EventSourceException(innerEx);
2046 m_EventSourceExceptionRecurenceCount--;
2051 private void ValidateEventOpcodeForTransfer(ref EventMetadata eventData,
string eventName)
2053 if (eventData.Descriptor.Opcode != 9 && eventData.Descriptor.Opcode != 240 && eventData.Descriptor.Opcode != 1)
2055 ThrowEventSourceException(eventName);
2061 if (opcode ==
EventOpcode.Info && eventName !=
null)
2063 if (eventName.EndsWith(
"Start"))
2067 if (eventName.EndsWith(
"Stop"))
2077 EventCommandEventArgs eventCommandEventArgs =
new EventCommandEventArgs(command, commandArguments,
this, listener, perEventSourceSessionId, etwSessionId, enable, level, matchAnyKeyword);
2078 lock (EventListener.EventListenersLock)
2080 if (m_completelyInited)
2082 m_deferredCommands =
null;
2083 DoCommand(eventCommandEventArgs);
2087 eventCommandEventArgs.nextCommand = m_deferredCommands;
2088 m_deferredCommands = eventCommandEventArgs;
2093 internal void DoCommand(EventCommandEventArgs commandArgs)
2095 if (m_provider !=
null)
2097 m_outOfBandMessageCount = 0;
2098 bool flag = commandArgs.perEventSourceSessionId > 0 && (long)commandArgs.perEventSourceSessionId <= 4L;
2101 EnsureDescriptorsInitialized();
2102 commandArgs.dispatcher = GetDispatcher(commandArgs.listener);
2103 if (commandArgs.dispatcher ==
null && commandArgs.listener !=
null)
2105 throw new ArgumentException(Environment.GetResourceString(
"EventSource_ListenerNotFound"));
2107 if (commandArgs.Arguments ==
null)
2113 for (
int i = 0; i < m_eventData.Length; i++)
2115 EnableEventForDispatcher(commandArgs.dispatcher, i, IsEnabledByDefault(i, commandArgs.enable, commandArgs.level, commandArgs.matchAnyKeyword));
2117 if (commandArgs.enable)
2119 if (!m_eventSourceEnabled)
2121 m_level = commandArgs.level;
2122 m_matchAnyKeyword = commandArgs.matchAnyKeyword;
2126 if (commandArgs.level > m_level)
2128 m_level = commandArgs.level;
2136 m_matchAnyKeyword |= commandArgs.matchAnyKeyword;
2140 bool flag2 = commandArgs.perEventSourceSessionId >= 0;
2141 if (commandArgs.perEventSourceSessionId == 0 && !commandArgs.enable)
2145 if (commandArgs.listener ==
null)
2149 commandArgs.perEventSourceSessionId = -commandArgs.perEventSourceSessionId;
2151 commandArgs.perEventSourceSessionId--;
2154 if (flag2 && commandArgs.dispatcher ==
null && !SelfDescribingEvents)
2156 SendManifest(m_rawManifest);
2158 if (flag2 && commandArgs.perEventSourceSessionId != -1)
2160 bool participateInSampling =
false;
2161 ParseCommandArgs(commandArgs.Arguments, out participateInSampling, out
string activityFilters, out
int sessionIdBit);
2162 if (commandArgs.listener ==
null && commandArgs.Arguments.Count > 0 && commandArgs.perEventSourceSessionId != sessionIdBit)
2164 throw new ArgumentException(Environment.GetResourceString(
"EventSource_SessionIdError", commandArgs.perEventSourceSessionId + 44, sessionIdBit + 44));
2166 if (commandArgs.listener ==
null)
2168 UpdateEtwSession(commandArgs.perEventSourceSessionId, commandArgs.etwSessionId, bEnable:
true, activityFilters, participateInSampling);
2172 ActivityFilter.UpdateFilter(ref commandArgs.listener.m_activityFilter,
this, 0, activityFilters);
2173 commandArgs.dispatcher.m_activityFilteringEnabled = participateInSampling;
2176 else if (!flag2 && commandArgs.listener ==
null && commandArgs.perEventSourceSessionId >= 0 && (
long)commandArgs.perEventSourceSessionId < 4L)
2180 if (commandArgs.enable)
2182 m_eventSourceEnabled =
true;
2185 m_eventCommandExecuted?.Invoke(
this, commandArgs);
2186 if (commandArgs.listener ==
null && !flag2 && commandArgs.perEventSourceSessionId != -1)
2188 UpdateEtwSession(commandArgs.perEventSourceSessionId, commandArgs.etwSessionId, bEnable:
false,
null, participateInSampling:
false);
2190 if (!commandArgs.enable)
2192 if (commandArgs.listener ==
null)
2194 for (
int j = 0; (long)j < 4L; j++)
2196 EtwSession etwSession = m_etwSessionIdMap[j];
2197 if (etwSession !=
null)
2199 ActivityFilter.DisableFilter(ref etwSession.m_activityFilter,
this);
2202 m_activityFilteringForETWEnabled =
new SessionMask(0u);
2203 m_curLiveSessions =
new SessionMask(0u);
2204 if (m_etwSessionIdMap !=
null)
2206 for (
int k = 0; (long)k < 4L; k++)
2208 m_etwSessionIdMap[k] =
null;
2211 if (m_legacySessions !=
null)
2213 m_legacySessions.Clear();
2218 ActivityFilter.DisableFilter(ref commandArgs.listener.m_activityFilter,
this);
2219 commandArgs.dispatcher.m_activityFilteringEnabled =
false;
2221 for (
int l = 0; l < m_eventData.Length; l++)
2223 bool enabledForAnyListener =
false;
2224 for (EventDispatcher eventDispatcher = m_Dispatchers; eventDispatcher !=
null; eventDispatcher = eventDispatcher.m_Next)
2226 if (eventDispatcher.m_EventEnabled[l])
2228 enabledForAnyListener =
true;
2232 m_eventData[l].EnabledForAnyListener = enabledForAnyListener;
2234 if (!AnyEventEnabled())
2238 m_eventSourceEnabled =
false;
2241 UpdateKwdTriggers(commandArgs.enable);
2245 if (commandArgs.Command ==
EventCommand.SendManifest && m_rawManifest !=
null)
2247 SendManifest(m_rawManifest);
2250 m_eventCommandExecuted?.Invoke(
this, commandArgs);
2252 if (m_completelyInited && ((commandArgs.listener !=
null) | flag))
2254 SessionMask sessions = SessionMask.FromId(commandArgs.perEventSourceSessionId);
2255 ReportActivitySamplingInfo(commandArgs.listener, sessions);
2258 catch (Exception ex)
2260 ReportOutOfBandMessage(
"ERROR: Exception in Command Processing for EventSource " +
Name +
": " + ex.Message, flush:
true);
2265 internal void UpdateEtwSession(
int sessionIdBit,
int etwSessionId,
bool bEnable,
string activityFilters,
bool participateInSampling)
2267 if ((
long)sessionIdBit < 4L)
2271 EtwSession etwSession = EtwSession.GetEtwSession(etwSessionId, bCreateIfNeeded:
true);
2272 ActivityFilter.UpdateFilter(ref etwSession.m_activityFilter,
this, sessionIdBit, activityFilters);
2273 m_etwSessionIdMap[sessionIdBit] = etwSession;
2274 m_activityFilteringForETWEnabled[sessionIdBit] = participateInSampling;
2278 EtwSession etwSession2 = EtwSession.GetEtwSession(etwSessionId);
2279 m_etwSessionIdMap[sessionIdBit] =
null;
2280 m_activityFilteringForETWEnabled[sessionIdBit] =
false;
2281 if (etwSession2 !=
null)
2283 ActivityFilter.DisableFilter(ref etwSession2.m_activityFilter,
this);
2284 EtwSession.RemoveEtwSession(etwSession2);
2287 m_curLiveSessions[sessionIdBit] = bEnable;
2292 if (m_legacySessions ==
null)
2296 EtwSession etwSession3 = EtwSession.GetEtwSession(etwSessionId, bCreateIfNeeded:
true);
2297 if (!m_legacySessions.Contains(etwSession3))
2299 m_legacySessions.Add(etwSession3);
2303 EtwSession etwSession4 = EtwSession.GetEtwSession(etwSessionId);
2304 if (etwSession4 !=
null)
2306 if (m_legacySessions !=
null)
2308 m_legacySessions.Remove(etwSession4);
2310 EtwSession.RemoveEtwSession(etwSession4);
2314 internal static bool ParseCommandArgs(
IDictionary<string, string> commandArguments, out
bool participateInSampling, out
string activityFilters, out
int sessionIdBit)
2317 participateInSampling =
false;
2318 if (commandArguments.
TryGetValue(
"ActivitySamplingStartEvent", out activityFilters))
2320 participateInSampling =
true;
2322 if (commandArguments.
TryGetValue(
"ActivitySampling", out
string value))
2324 if (
string.Compare(value,
"false",
StringComparison.OrdinalIgnoreCase) == 0 || value ==
"0")
2326 participateInSampling =
false;
2330 participateInSampling =
true;
2334 if (!commandArguments.
TryGetValue(
"EtwSessionKeyword", out
string value2) || !
int.TryParse(value2, out result2) || result2 < 44 || (long)result2 >= 48L)
2341 sessionIdBit = result2 - 44;
2346 internal void UpdateKwdTriggers(
bool enable)
2350 ulong num = (ulong)m_matchAnyKeyword;
2353 num = ulong.MaxValue;
2355 m_keywordTriggers = 0
L;
2356 for (
int i = 0; (long)i < 4L; i++)
2358 EtwSession etwSession = m_etwSessionIdMap[i];
2359 if (etwSession !=
null)
2361 ActivityFilter activityFilter = etwSession.m_activityFilter;
2362 ActivityFilter.UpdateKwdTriggers(activityFilter, m_guid,
this, (
EventKeywords)num);
2368 m_keywordTriggers = 0
L;
2372 internal bool EnableEventForDispatcher(EventDispatcher dispatcher,
int eventId,
bool value)
2374 if (dispatcher ==
null)
2376 if (eventId >= m_eventData.Length)
2380 if (m_provider !=
null)
2382 m_eventData[eventId].EnabledForETW = value;
2387 if (eventId >= dispatcher.m_EventEnabled.Length)
2391 dispatcher.m_EventEnabled[eventId] = value;
2394 m_eventData[eventId].EnabledForAnyListener =
true;
2400 private bool AnyEventEnabled()
2402 for (
int i = 0; i < m_eventData.Length; i++)
2404 if (m_eventData[i].EnabledForETW || m_eventData[i].EnabledForAnyListener)
2412 [SecuritySafeCritical]
2413 private void EnsureDescriptorsInitialized()
2415 if (m_eventData ==
null)
2417 m_rawManifest = CreateManifestAndDescriptors(GetType(), Name,
this);
2418 foreach (WeakReference s_EventSource
in EventListener.s_EventSources)
2420 EventSource eventSource = s_EventSource.Target as EventSource;
2421 if (eventSource !=
null && eventSource.Guid == m_guid && !eventSource.IsDisposed && eventSource !=
this)
2423 throw new ArgumentException(Environment.GetResourceString(
"EventSource_EventSourceGuidInUse", m_guid));
2426 for (EventDispatcher eventDispatcher = m_Dispatchers; eventDispatcher !=
null; eventDispatcher = eventDispatcher.m_Next)
2428 if (eventDispatcher.m_EventEnabled ==
null)
2430 eventDispatcher.m_EventEnabled =
new bool[m_eventData.Length];
2434 if (s_currentPid == 0)
2436 s_currentPid = Win32Native.GetCurrentProcessId();
2440 [SecuritySafeCritical]
2441 private unsafe
bool SendManifest(
byte[] rawManifest)
2444 if (rawManifest ==
null)
2448 fixed (
byte* ptr2 = rawManifest)
2450 EventDescriptor eventDescriptor =
new EventDescriptor(65534, 1, 0, 0, 254, 65534, 72057594037927935L);
2451 ManifestEnvelope manifestEnvelope =
default(ManifestEnvelope);
2452 manifestEnvelope.Format = ManifestEnvelope.ManifestFormats.SimpleXmlFormat;
2453 manifestEnvelope.MajorVersion = 1;
2454 manifestEnvelope.MinorVersion = 0;
2455 manifestEnvelope.Magic = 91;
2456 int num = rawManifest.Length;
2457 manifestEnvelope.ChunkNumber = 0;
2458 EventProvider.EventData* ptr = stackalloc EventProvider.EventData[2];
2459 ptr->Ptr = (ulong)(&manifestEnvelope);
2460 ptr->Size = (uint)
sizeof(ManifestEnvelope);
2462 ptr[1].Ptr = (ulong)ptr2;
2463 ptr[1].Reserved = 0u;
2468 manifestEnvelope.TotalChunks = (ushort)((num + (num2 - 1)) / num2);
2471 ptr[1].Size = (uint)Math.Min(num, num2);
2472 if (m_provider !=
null && !m_provider.WriteEvent(ref eventDescriptor,
null,
null, 2, (IntPtr)(
void*)ptr))
2474 if (EventProvider.GetLastWriteEventError() != EventProvider.WriteEventErrorCode.EventTooBig || manifestEnvelope.ChunkNumber != 0 || num2 <= 256)
2477 if (ThrowOnEventWriteErrors)
2479 ThrowEventSourceException(
"SendManifest");
2487 ptr[1].Ptr += (uint)num2;
2488 manifestEnvelope.ChunkNumber++;
2489 if ((
int)manifestEnvelope.ChunkNumber % 5 == 0)
2504 Attribute result =
null;
2507 if (num < customAttributes.Length)
2509 object obj = customAttributes[num];
2510 result = (Attribute)obj;
2514 string fullName = attributeType.FullName;
2519 Attribute attribute =
null;
2522 attribute = (Attribute)Activator.CreateInstance(attributeType, customAttribute.
ConstructorArguments[0].Value);
2526 attribute = (Attribute)Activator.CreateInstance(attributeType);
2528 if (attribute !=
null)
2530 Type type = attribute.GetType();
2535 if (property.PropertyType.IsEnum)
2537 obj2 =
Enum.Parse(property.PropertyType, obj2.ToString());
2539 property.SetValue(attribute, obj2,
null);
2548 private static bool AttributeTypeNamesMatch(Type attributeType, Type reflectedAttributeType)
2550 if (!(attributeType == reflectedAttributeType) && !
string.Equals(attributeType.FullName, reflectedAttributeType.FullName,
StringComparison.Ordinal))
2552 if (
string.Equals(attributeType.Name, reflectedAttributeType.Name,
StringComparison.Ordinal) && attributeType.Namespace.EndsWith(
"Diagnostics.Tracing"))
2554 return reflectedAttributeType.Namespace.EndsWith(
"Diagnostics.Tracing");
2561 private static Type GetEventSourceBaseType(Type eventSourceType,
bool allowEventSourceOverride,
bool reflectionOnly)
2563 if (eventSourceType.BaseType() ==
null)
2569 eventSourceType = eventSourceType.BaseType();
2571 while (eventSourceType !=
null && eventSourceType.IsAbstract());
2572 if (eventSourceType !=
null)
2574 if (!allowEventSourceOverride)
2576 if ((reflectionOnly && eventSourceType.FullName != typeof(EventSource).FullName) || (!reflectionOnly && eventSourceType != typeof(EventSource)))
2581 else if (eventSourceType.Name !=
"EventSource")
2586 return eventSourceType;
2591 ManifestBuilder manifestBuilder =
null;
2592 bool flag = source ==
null || !source.SelfDescribingEvents;
2593 Exception ex =
null;
2594 byte[] result =
null;
2603 EventMetadata[] eventData =
null;
2607 eventData =
new EventMetadata[methods.Length + 1];
2608 eventData[0].Name =
"";
2611 EventSourceAttribute eventSourceAttribute = (EventSourceAttribute)GetCustomAttributeHelper(eventSourceType, typeof(EventSourceAttribute), flags);
2612 if (eventSourceAttribute !=
null && eventSourceAttribute.LocalizationResources !=
null)
2614 resources =
new ResourceManager(eventSourceAttribute.LocalizationResources, eventSourceType.Assembly());
2616 manifestBuilder =
new ManifestBuilder(GetName(eventSourceType, flags), GetGuid(eventSourceType), eventSourceDllName, resources, flags);
2617 manifestBuilder.StartEvent(
"EventSourceMessage",
new EventAttribute(0)
2622 manifestBuilder.AddEventParameter(typeof(
string),
"message");
2623 manifestBuilder.EndEvent();
2628 manifestBuilder.ManifestError(Environment.GetResourceString(
"EventSource_TypeMustDeriveFromEventSource"));
2630 if (!eventSourceType.IsAbstract() && !eventSourceType.IsSealed())
2632 manifestBuilder.ManifestError(Environment.GetResourceString(
"EventSource_TypeMustBeSealedOrAbstract"));
2635 string[] array =
new string[3]
2641 foreach (
string text
in array)
2643 Type nestedType = eventSourceType.GetNestedType(text);
2644 if (nestedType !=
null)
2646 if (eventSourceType.IsAbstract())
2648 manifestBuilder.ManifestError(Environment.GetResourceString(
"EventSource_AbstractMustNotDeclareKTOC", nestedType.Name));
2653 foreach (
FieldInfo staticField
in fields)
2655 AddProviderEnumKind(manifestBuilder, staticField, text);
2660 manifestBuilder.AddKeyword(
"Session3", 17592186044416uL);
2661 manifestBuilder.AddKeyword(
"Session2", 35184372088832uL);
2662 manifestBuilder.AddKeyword(
"Session1", 70368744177664uL);
2663 manifestBuilder.AddKeyword(
"Session0", 140737488355328uL);
2664 if (eventSourceType != typeof(EventSource))
2669 EventAttribute eventAttribute = (EventAttribute)GetCustomAttributeHelper(methodInfo, typeof(EventAttribute), flags);
2670 if (eventAttribute !=
null && source !=
null && eventAttribute.EventId <= 3 && source.Guid.Equals(AspNetEventSourceGuid))
2676 if (eventSourceType.IsAbstract())
2678 if (eventAttribute !=
null)
2680 manifestBuilder.ManifestError(Environment.GetResourceString(
"EventSource_AbstractMustNotDeclareEventMethods", methodInfo.
Name, eventAttribute.EventId));
2685 if (eventAttribute ==
null)
2687 if (methodInfo.
ReturnType != typeof(
void) || methodInfo.
IsVirtual || GetCustomAttributeHelper(methodInfo, typeof(NonEventAttribute), flags) !=
null)
2691 EventAttribute eventAttribute2 =
new EventAttribute(num);
2692 eventAttribute = eventAttribute2;
2694 else if (eventAttribute.EventId <= 0)
2696 manifestBuilder.ManifestError(Environment.GetResourceString(
"EventSource_NeedPositiveId", methodInfo.
Name), runtimeCritical:
true);
2699 if (methodInfo.
Name.LastIndexOf(
'.') >= 0)
2701 manifestBuilder.ManifestError(Environment.GetResourceString(
"EventSource_EventMustNotBeExplicitImplementation", methodInfo.
Name, eventAttribute.EventId));
2704 string name = methodInfo.
Name;
2707 bool flag2 = eventAttribute.Task ==
EventTask.None;
2710 eventAttribute.Task = (
EventTask)(65534 - eventAttribute.EventId);
2712 if (!eventAttribute.IsOpcodeSet)
2714 eventAttribute.Opcode = GetOpcodeWithDefault(
EventOpcode.Info, name);
2720 string text2 = name.Substring(0, name.Length -
"Start".Length);
2721 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)
2723 manifestBuilder.AddTask(text2, (
int)eventAttribute.Task);
2726 else if (eventAttribute.Opcode ==
EventOpcode.Stop)
2728 int num2 = eventAttribute.EventId - 1;
2729 if (eventData !=
null && num2 < eventData.Length)
2731 EventMetadata eventMetadata = eventData[num2];
2732 string text3 = name.Substring(0, name.Length -
"Stop".Length);
2733 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)
2735 eventAttribute.Task = (
EventTask)eventMetadata.Descriptor.Task;
2741 throw new ArgumentException(Environment.GetResourceString(
"EventSource_StopsFollowStarts"));
2746 bool hasRelatedActivityID = RemoveFirstArgIfRelatedActivityId(ref args);
2747 if (source ==
null || !source.SelfDescribingEvents)
2749 manifestBuilder.StartEvent(name, eventAttribute);
2750 for (
int l = 0; l < args.Length; l++)
2752 manifestBuilder.AddEventParameter(args[l].ParameterType, args[l].Name);
2754 manifestBuilder.EndEvent();
2758 DebugCheckEvent(ref eventsByName, eventData, methodInfo, eventAttribute, manifestBuilder, flags);
2759 if (eventAttribute.Channel != 0)
2761 eventAttribute.Keywords |= (
EventKeywords)manifestBuilder.GetChannelKeyword(eventAttribute.Channel);
2763 string key =
"event_" + name;
2765 if (localizedMessage !=
null)
2767 eventAttribute.Message = localizedMessage;
2769 AddEventDescriptor(ref eventData, name, eventAttribute, args, hasRelatedActivityID);
2775 NameInfo.ReserveEventIDsBelow(num);
2778 TrimEventDescriptors(ref eventData);
2779 source.m_eventData = eventData;
2780 source.m_channelData = manifestBuilder.GetChannelData();
2782 if (!eventSourceType.IsAbstract() && (source ==
null || !source.SelfDescribingEvents))
2789 result = manifestBuilder.CreateManifest();
2792 catch (Exception ex2)
2800 if ((flags &
EventManifestOptions.Strict) != 0 && (manifestBuilder.Errors.Count > 0 || ex !=
null))
2802 string text4 =
string.Empty;
2803 if (manifestBuilder.Errors.Count > 0)
2806 foreach (
string error
in manifestBuilder.Errors)
2810 text4 += Environment.NewLine;
2818 text4 =
"Unexpected error: " + ex.Message;
2820 throw new ArgumentException(text4, ex);
2829 private static bool RemoveFirstArgIfRelatedActivityId(ref
ParameterInfo[] args)
2831 if (args.Length != 0 && args[0].ParameterType == typeof(Guid) &&
string.Compare(args[0].Name,
"relatedActivityId",
StringComparison.OrdinalIgnoreCase) == 0)
2834 Array.Copy(args, 1, array, 0, args.Length - 1);
2841 private static void AddProviderEnumKind(ManifestBuilder manifest,
FieldInfo staticField,
string providerEnumKind)
2845 if ((!flag && fieldType == typeof(
EventOpcode)) || AttributeTypeNamesMatch(fieldType, typeof(
EventOpcode)))
2847 if (!(providerEnumKind !=
"Opcodes"))
2850 manifest.AddOpcode(staticField.
Name, value);
2854 else if ((!flag && fieldType == typeof(
EventTask)) || AttributeTypeNamesMatch(fieldType, typeof(
EventTask)))
2856 if (!(providerEnumKind !=
"Tasks"))
2859 manifest.AddTask(staticField.
Name, value2);
2869 if (!(providerEnumKind !=
"Keywords"))
2872 manifest.AddKeyword(staticField.
Name, value3);
2876 manifest.ManifestError(Environment.GetResourceString(
"EventSource_EnumKindMismatch", staticField.
Name, staticField.
FieldType.
Name, providerEnumKind));
2879 private static void AddEventDescriptor(ref EventMetadata[] eventData,
string eventName, EventAttribute eventAttribute,
ParameterInfo[] eventParameters,
bool hasRelatedActivityID)
2881 if (eventData ==
null || eventData.Length <= eventAttribute.EventId)
2883 EventMetadata[] array =
new EventMetadata[Math.Max(eventData.Length + 16, eventAttribute.EventId + 1)];
2884 Array.Copy(eventData, array, eventData.Length);
2887 eventData[eventAttribute.EventId].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());
2888 eventData[eventAttribute.EventId].Tags = eventAttribute.Tags;
2889 eventData[eventAttribute.EventId].Name = eventName;
2890 eventData[eventAttribute.EventId].Parameters = eventParameters;
2891 eventData[eventAttribute.EventId].Message = eventAttribute.Message;
2892 eventData[eventAttribute.EventId].ActivityOptions = eventAttribute.ActivityOptions;
2893 eventData[eventAttribute.EventId].HasRelatedActivityID = hasRelatedActivityID;
2896 private static void TrimEventDescriptors(ref EventMetadata[] eventData)
2898 int num = eventData.Length;
2902 if (eventData[num].Descriptor.EventId != 0)
2907 if (eventData.Length - num > 2)
2909 EventMetadata[] array =
new EventMetadata[num + 1];
2910 Array.Copy(eventData, array, array.Length);
2915 internal void AddListener(EventListener listener)
2917 lock (EventListener.EventListenersLock)
2919 bool[] eventEnabled =
null;
2920 if (m_eventData !=
null)
2922 eventEnabled =
new bool[m_eventData.Length];
2924 m_Dispatchers =
new EventDispatcher(m_Dispatchers, eventEnabled, listener);
2925 listener.OnEventSourceCreated(
this);
2931 int eventId = eventAttribute.EventId;
2932 string name = method.
Name;
2933 int helperCallFirstArg = GetHelperCallFirstArg(method);
2934 if (helperCallFirstArg >= 0 && eventId != helperCallFirstArg)
2936 manifest.ManifestError(Environment.GetResourceString(
"EventSource_MismatchIdToWriteEvent", name, eventId, helperCallFirstArg), runtimeCritical:
true);
2938 if (eventId < eventData.Length && eventData[eventId].Descriptor.EventId != 0)
2940 manifest.ManifestError(Environment.GetResourceString(
"EventSource_EventIdReused", name, eventId, eventData[eventId].Name), runtimeCritical:
true);
2942 for (
int i = 0; i < eventData.Length; i++)
2944 if (eventData[i].Name !=
null && eventData[i].Descriptor.Task == (
int)eventAttribute.Task && (
EventOpcode)eventData[i].Descriptor.Opcode == eventAttribute.Opcode)
2946 manifest.ManifestError(Environment.GetResourceString(
"EventSource_TaskOpcodePairReused", name, eventId, eventData[i].Name, i));
2953 if (eventAttribute.Opcode != 0)
2956 if (eventAttribute.Task ==
EventTask.None)
2963 if (eventAttribute.Opcode !=
EventOpcode.Start && eventAttribute.Opcode !=
EventOpcode.Stop && eventAttribute.Task == eventTask)
2970 manifest.ManifestError(Environment.GetResourceString(
"EventSource_EventMustHaveTaskIfNonDefaultOpcode", name, eventId));
2973 if (eventsByName ==
null)
2977 if (eventsByName.ContainsKey(name))
2979 manifest.ManifestError(Environment.GetResourceString(
"EventSource_EventNameReused", name), runtimeCritical:
true);
2981 eventsByName[name] = name;
2984 [SecuritySafeCritical]
2985 private static int GetHelperCallFirstArg(
MethodInfo method)
2990 for (
int i = 0; i < iLAsByteArray.Length; i++)
2992 switch (iLAsByteArray[i])
3008 if (i > 0 && iLAsByteArray[i - 1] == 2)
3010 num = iLAsByteArray[i] - 22;
3014 if (i > 0 && iLAsByteArray[i - 1] == 2)
3016 num = iLAsByteArray[i + 1];
3027 for (
int j = i + 1; j < iLAsByteArray.Length; j++)
3029 if (iLAsByteArray[j] == 42)
3033 if (iLAsByteArray[j] != 0)
3057 if (i < iLAsByteArray.Length && iLAsByteArray[i] < 6)
3092 internal void ReportOutOfBandMessage(
string msg,
bool flush)
3096 Debugger.Log(0,
null, msg +
"\r\n");
3097 if (m_outOfBandMessageCount < 15)
3099 m_outOfBandMessageCount++;
3102 if (m_outOfBandMessageCount != 16)
3104 m_outOfBandMessageCount = 16;
3105 msg =
"Reached message limit. End of EventSource error messages.";
3110 WriteEventString(
EventLevel.LogAlways, -1L, msg);
3111 WriteStringToAllListeners(
"EventSourceMessage", msg);
3122 if ((settings & eventSourceSettings) == eventSourceSettings)
3124 throw new ArgumentException(Environment.GetResourceString(
"EventSource_InvalidEventFormat"),
"settings");
3133 private void ReportActivitySamplingInfo(EventListener listener, SessionMask sessions)
3135 for (
int i = 0; (long)i < 4L; i++)
3139 ActivityFilter activityFilter;
3140 if (listener ==
null)
3142 EtwSession etwSession = m_etwSessionIdMap[i];
3143 activityFilter = etwSession.m_activityFilter;
3147 activityFilter = listener.m_activityFilter;
3149 if (activityFilter !=
null)
3151 SessionMask m =
default(SessionMask);
3153 foreach (Tuple<int, int> item
in activityFilter.GetFilterAsTuple(m_guid))
3155 WriteStringToListener(listener,
string.Format(
CultureInfo.
InvariantCulture,
"Session {0}: {1} = {2}", i, item.Item1, item.Item2), m);
3157 bool flag = (listener ==
null) ? m_activityFilteringForETWEnabled[i] : GetDispatcher(listener).m_activityFilteringEnabled;
3158 WriteStringToListener(listener,
string.Format(
CultureInfo.
InvariantCulture,
"Session {0}: Activity Sampling support: {1}", i, flag ?
"enabled" :
"disabled"), m);
3168 [__DynamicallyInvokable]
3181 [__DynamicallyInvokable]
3183 : this(eventSourceName, config, (string[])null)
3195 [__DynamicallyInvokable]
3197 : this((eventSourceName == null) ? default(
Guid) : GenerateGuidFromName(eventSourceName.ToUpperInvariant()), eventSourceName, config, traits)
3199 if (eventSourceName ==
null)
3209 [SecuritySafeCritical]
3210 [__DynamicallyInvokable]
3213 if (eventName ==
null)
3220 EmptyStruct data =
default(EmptyStruct);
3221 WriteImpl(eventName, ref options, ref data,
null,
null);
3230 [SecuritySafeCritical]
3231 [__DynamicallyInvokable]
3234 if (eventName ==
null)
3240 EmptyStruct data =
default(EmptyStruct);
3241 WriteImpl(eventName, ref options, ref data,
null,
null);
3249 [SecuritySafeCritical]
3250 [__DynamicallyInvokable]
3251 public void Write<T>(
string eventName, T data)
3256 WriteImpl(eventName, ref options, ref data,
null,
null);
3265 [SecuritySafeCritical]
3266 [__DynamicallyInvokable]
3271 WriteImpl(eventName, ref options, ref data,
null,
null);
3280 [SecuritySafeCritical]
3281 [__DynamicallyInvokable]
3286 WriteImpl(eventName, ref options, ref data,
null,
null);
3297 [SecuritySafeCritical]
3298 [__DynamicallyInvokable]
3303 fixed (
Guid* pActivityId = &activityId)
3305 fixed (
Guid* ptr = &relatedActivityId)
3307 WriteImpl(eventName, ref options, ref data, pActivityId, (
Guid*)(
long)((relatedActivityId ==
Guid.
Empty) ? ((
IntPtr)(
void*)
null) : ((
IntPtr)ptr)));
3313 [SecuritySafeCritical]
3314 private unsafe
void WriteMultiMerge(
string eventName, ref
EventSourceOptions options, TraceLoggingEventTypes eventTypes,
Guid* activityID,
Guid* childActivityID, params
object[] values)
3318 byte level = ((options.valuesSet & 4) != 0) ? options.level : eventTypes.level;
3319 EventKeywords keywords = ((options.valuesSet & 1) != 0) ? options.keywords : eventTypes.keywords;
3322 WriteMultiMergeInner(eventName, ref options, eventTypes, activityID, childActivityID, values);
3327 [SecuritySafeCritical]
3328 private unsafe
void WriteMultiMergeInner(
string eventName, ref EventSourceOptions options, TraceLoggingEventTypes eventTypes, Guid* activityID, Guid* childActivityID, params
object[] values)
3331 byte level = ((options.valuesSet & 4) != 0) ? options.level : eventTypes.level;
3332 byte opcode = ((options.valuesSet & 8) != 0) ? options.opcode : eventTypes.opcode;
3333 EventTags tags = ((options.valuesSet & 2) != 0) ? options.tags : eventTypes.Tags;
3334 EventKeywords keywords = ((options.valuesSet & 1) != 0) ? options.keywords : eventTypes.keywords;
3335 NameInfo nameInfo = eventTypes.GetNameInfo(eventName ?? eventTypes.Name, tags);
3336 if (nameInfo !=
null)
3338 num = nameInfo.identity;
3339 EventDescriptor eventDescriptor =
new EventDescriptor(num, level, opcode, (
long)keywords);
3340 int pinCount = eventTypes.pinCount;
3341 byte* scratch = stackalloc
byte[(int)checked(unchecked((ulong)(uint)eventTypes.scratchSize) * 1uL)];
3342 EventData* ptr = stackalloc EventData[eventTypes.dataCount + 3];
3344 byte[] array = providerMetadata;
3345 fixed (
byte* pointer = array)
3347 byte[] nameMetadata = nameInfo.nameMetadata;
3348 fixed (
byte* pointer2 = nameMetadata)
3350 byte[] typeMetadata = eventTypes.typeMetadata;
3351 fixed (
byte* pointer3 = typeMetadata)
3353 ptr->SetMetadata(pointer, providerMetadata.Length, 2);
3354 ptr[1].SetMetadata(pointer2, nameInfo.nameMetadata.Length, 1);
3355 ptr[2].SetMetadata(pointer3, eventTypes.typeMetadata.Length, 1);
3359 DataCollector.ThreadInstance.Enable(scratch, eventTypes.scratchSize, ptr + 3, eventTypes.dataCount, ptr2, pinCount);
3360 for (
int i = 0; i < eventTypes.typeInfos.Length; i++)
3362 eventTypes.typeInfos[i].WriteObjectData(TraceLoggingDataCollector.Instance, values[i]);
3364 WriteEventRaw(eventName, ref eventDescriptor, activityID, childActivityID, (
int)(DataCollector.ThreadInstance.Finish() - ptr), (IntPtr)(
void*)ptr);
3368 WriteCleanup(ptr2, pinCount);
3376 [SecuritySafeCritical]
3377 internal unsafe
void WriteMultiMerge(
string eventName, ref EventSourceOptions options, TraceLoggingEventTypes eventTypes, Guid* activityID, Guid* childActivityID, EventData* data)
3381 fixed (EventSourceOptions* ptr2 = &options)
3383 EventDescriptor descriptor;
3384 NameInfo nameInfo = UpdateDescriptor(eventName, eventTypes, ref options, out descriptor);
3385 if (nameInfo !=
null)
3387 EventData* ptr = stackalloc EventData[eventTypes.dataCount + eventTypes.typeInfos.Length * 2 + 3];
3388 byte[] array = providerMetadata;
3389 fixed (
byte* pointer = array)
3391 byte[] nameMetadata = nameInfo.nameMetadata;
3392 fixed (
byte* pointer2 = nameMetadata)
3394 byte[] typeMetadata = eventTypes.typeMetadata;
3395 fixed (
byte* pointer3 = typeMetadata)
3397 ptr->SetMetadata(pointer, providerMetadata.Length, 2);
3398 ptr[1].SetMetadata(pointer2, nameInfo.nameMetadata.Length, 1);
3399 ptr[2].SetMetadata(pointer3, eventTypes.typeMetadata.Length, 1);
3401 for (
int i = 0; i < eventTypes.typeInfos.Length; i++)
3403 if (eventTypes.typeInfos[i].DataType == typeof(
string))
3405 ptr[num].m_Ptr = (long)(&ptr[num + 1].m_Size);
3406 ptr[num].m_Size = 2;
3408 ptr[num].m_Ptr = data[i].m_Ptr;
3409 ptr[num].m_Size = data[i].m_Size - 2;
3414 ptr[num].m_Ptr = data[i].m_Ptr;
3415 ptr[num].m_Size = data[i].m_Size;
3416 if (data[i].m_Size == 4 && eventTypes.typeInfos[i].DataType == typeof(
bool))
3418 ptr[num].m_Size = 1;
3423 WriteEventRaw(eventName, ref descriptor, activityID, childActivityID, num, (IntPtr)(
void*)ptr);
3432 [SecuritySafeCritical]
3433 private unsafe
void WriteImpl<T>(
string eventName, ref EventSourceOptions options, ref T data, Guid* pActivityId, Guid* pRelatedActivityId)
3437 SimpleEventTypes<T> instance = SimpleEventTypes<T>.Instance;
3440 fixed (EventSourceOptions* ptr3 = &options)
3442 options.Opcode = (options.IsOpcodeSet ? options.Opcode : GetOpcodeWithDefault(options.Opcode, eventName));
3443 EventDescriptor descriptor;
3444 NameInfo nameInfo = UpdateDescriptor(eventName, instance, ref options, out descriptor);
3445 if (nameInfo !=
null)
3447 int pinCount = instance.pinCount;
3448 byte* scratch = stackalloc
byte[(int)checked(unchecked((ulong)(uint)instance.scratchSize) * 1uL)];
3449 EventData* ptr = stackalloc EventData[instance.dataCount + 3];
3453 byte[] array = providerMetadata;
3454 fixed (
byte* pointer = array)
3456 byte[] nameMetadata = nameInfo.nameMetadata;
3457 fixed (
byte* pointer2 = nameMetadata)
3459 byte[] typeMetadata = instance.typeMetadata;
3460 fixed (
byte* pointer3 = typeMetadata)
3462 ptr->SetMetadata(pointer, providerMetadata.Length, 2);
3463 ptr[1].SetMetadata(pointer2, nameInfo.nameMetadata.Length, 1);
3464 ptr[2].SetMetadata(pointer3, instance.typeMetadata.Length, 1);
3467 Guid activityId = Guid.Empty;
3468 Guid relatedActivityId = Guid.Empty;
3474 m_activityTracker.OnStart(m_name, eventName, 0, ref activityId, ref relatedActivityId, options.ActivityOptions);
3477 m_activityTracker.OnStop(m_name, eventName, 0, ref activityId);
3480 if (activityId != Guid.Empty)
3482 pActivityId = &activityId;
3484 if (relatedActivityId != Guid.Empty)
3486 pRelatedActivityId = &relatedActivityId;
3491 DataCollector.ThreadInstance.Enable(scratch, instance.scratchSize, ptr + 3, instance.dataCount, ptr2, pinCount);
3492 instance.typeInfo.WriteData(TraceLoggingDataCollector.Instance, ref data);
3493 WriteEventRaw(eventName, ref descriptor, pActivityId, pRelatedActivityId, (
int)(DataCollector.ThreadInstance.Finish() - ptr), (IntPtr)(
void*)ptr);
3494 if (m_Dispatchers !=
null)
3496 EventPayload payload = (EventPayload)instance.typeInfo.GetData(data);
3497 WriteToAllListeners(eventName, ref descriptor, nameInfo.tags, pActivityId, payload);
3500 catch (Exception ex)
3502 if (ex is EventSourceException)
3506 ThrowEventSourceException(eventName, ex);
3510 WriteCleanup(ptr2, pinCount);
3526 catch (Exception ex2)
3528 if (ex2 is EventSourceException)
3532 ThrowEventSourceException(eventName, ex2);
3537 private unsafe
void WriteToAllListeners(
string eventName, ref EventDescriptor eventDescriptor,
EventTags tags, Guid* pActivityId, EventPayload payload)
3539 EventWrittenEventArgs eventWrittenEventArgs =
new EventWrittenEventArgs(
this);
3540 eventWrittenEventArgs.EventName = eventName;
3541 eventWrittenEventArgs.m_keywords = (
EventKeywords)eventDescriptor.Keywords;
3542 eventWrittenEventArgs.m_opcode = (
EventOpcode)eventDescriptor.Opcode;
3543 eventWrittenEventArgs.m_tags = tags;
3544 eventWrittenEventArgs.EventId = -1;
3545 if (pActivityId !=
null)
3547 eventWrittenEventArgs.RelatedActivityId = *pActivityId;
3549 if (payload !=
null)
3554 DispatchToAllListeners(-1, pActivityId, eventWrittenEventArgs);
3557 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.Success)]
3560 private unsafe
void WriteCleanup(
GCHandle* pPins,
int cPins)
3562 DataCollector.ThreadInstance.Disable();
3563 for (
int i = 0; i != cPins; i++)
3565 if (IntPtr.Zero != (IntPtr)pPins[i])
3572 private void InitializeProviderMetadata()
3574 if (m_traits !=
null)
3577 for (
int i = 0; i < m_traits.Length - 1; i += 2)
3579 if (!m_traits[i].StartsWith(
"ETW_"))
3583 string text = m_traits[i].Substring(4);
3584 if (!
byte.TryParse(text, out
byte result))
3586 if (!(text ==
"GROUP"))
3588 throw new ArgumentException(Environment.GetResourceString(
"UnknownEtwTrait", text),
"traits");
3592 string value = m_traits[i + 1];
3593 int count = list.Count;
3597 int num = AddValueToMetaData(list, value) + 3;
3598 list[count] = (byte)num;
3599 list[count + 1] = (byte)(num >> 8);
3601 providerMetadata = Statics.MetadataForString(Name, 0, list.Count, 0);
3602 int num2 = providerMetadata.Length - list.Count;
3603 foreach (
byte item
in list)
3605 providerMetadata[num2++] = item;
3610 providerMetadata = Statics.MetadataForString(Name, 0, 0, 0);
3614 private static int AddValueToMetaData(
List<byte> metaData,
string value)
3616 if (value.Length == 0)
3620 int count = metaData.
Count;
3628 metaData.
AddRange(
new Guid(value).ToByteArray());
3631 for (
int i = 1; i < value.Length; i++)
3633 if (value[i] !=
' ')
3635 if (i + 1 >= value.Length)
3637 throw new ArgumentException(Environment.GetResourceString(
"EvenHexDigits"),
"traits");
3639 metaData.
Add((
byte)(HexDigit(value[i]) * 16 + HexDigit(value[i + 1])));
3650 throw new ArgumentException(Environment.GetResourceString(
"IllegalValue", value),
"traits");
3652 return metaData.
Count - count;
3655 private static int HexDigit(
char c)
3657 if (
'0' <= c && c <=
'9')
3665 if (
'A' <= c && c <=
'F')
3669 throw new ArgumentException(Environment.GetResourceString(
"BadHexDigit", c),
"traits");
3672 private NameInfo UpdateDescriptor(
string name, TraceLoggingEventTypes eventInfo, ref EventSourceOptions options, out EventDescriptor descriptor)
3674 NameInfo nameInfo =
null;
3675 int traceloggingId = 0;
3676 byte level = ((options.valuesSet & 4) != 0) ? options.level : eventInfo.level;
3677 byte opcode = ((options.valuesSet & 8) != 0) ? options.opcode : eventInfo.opcode;
3678 EventTags tags = ((options.valuesSet & 2) != 0) ? options.tags : eventInfo.Tags;
3679 EventKeywords keywords = ((options.valuesSet & 1) != 0) ? options.keywords : eventInfo.keywords;
3682 nameInfo = eventInfo.GetNameInfo(name ?? eventInfo.Name, tags);
3683 traceloggingId = nameInfo.identity;
3685 descriptor =
new EventDescriptor(traceloggingId, level, opcode, (
long)keywords);
Obtains information about the attributes of a member and provides access to member metadata.
Represents a character encoding.To browse the .NET Framework source code for this type,...
A platform-specific type that is used to represent a pointer or a handle.
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Discovers the attributes of a parameter and provides access to parameter metadata.
virtual Assembly Assembly
Gets the appropriate T:System.Reflection.Assembly for this instance of T:System.Reflection....
Allows the event tracing for Windows (ETW) name to be defined independently of the name of the event ...
unsafe void WriteEvent(int eventId, long arg1, string arg2)
Writes an event by using the provided event identifier and 64-bit integer, and string arguments.
string Name
The friendly name of the class that is derived from the event source.
EventActivityOptions
Specifies the tracking of activity start and stop events.
virtual IList< CustomAttributeNamedArgument > NamedArguments
Gets the list of named arguments specified for the attribute instance represented by the T:System....
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
unsafe string GetString(byte *bytes, int byteCount)
When overridden in a derived class, decodes a specified number of bytes starting at a specified addre...
The ETW listener should use a manifest-based format when raising events. Setting this option is a dir...
The ETW listener should use self-describing event format. This is the default option when creating a ...
unsafe void WriteEventWithRelatedActivityIdCore(int eventId, Guid *relatedActivityId, int eventDataCount, EventData *data)
[Supported in the .NET Framework 4.5.1 and later versions] Writes an event that indicates that the cu...
Specifies overrides of default event settings such as the log level, keywords and operation code when...
EventOpcode
Defines the standard operation codes that the event source attaches to events.
abstract Type FieldType
Gets the type of this field object.
Represents a named argument of a custom attribute in the reflection-only context.
ReflectionPermissionFlag
Specifies the permitted use of the N:System.Reflection and N:System.Reflection.Emit namespaces.
virtual byte [] GetBytes(char[] chars)
When overridden in a derived class, encodes all the characters in the specified character array into ...
int Count
Gets the number of elements contained in the T:System.Collections.Generic.List`1.
Provides methods for enabling and disabling events from event sources.
void Dispose()
Releases all resources used by the current instance of the T:System.Diagnostics.Tracing....
Provides the base class for a generic read-only collection.
Discovers the attributes of a method and provides access to method metadata.
static void SuppressFinalize(object obj)
Requests that the common language runtime not call the finalizer for the specified object.
string GetTrait(string key)
Gets the trait value associated with the specified key.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
EventSource(string eventSourceName, EventSourceSettings config)
Creates a new instance of the T:System.Diagnostics.Tracing.EventSource class with the specified name ...
static string GetName(Type eventSourceType)
Gets the friendly name of the event source.
unsafe void WriteEvent(int eventId, string arg1, int arg2)
Writes an event by using the provided event identifier and arguments.
EventManifestOptions
Specifies how the ETW manifest for the event source is generated.
EventKeywords
Defines the standard keywords that apply to events.
bool IsVirtual
Gets a value indicating whether the method is virtual.
static string GenerateManifest(Type eventSourceType, string assemblyPathToIncludeInManifest, EventManifestOptions flags)
Returns a string of the XML manifest that is associated with the current event source.
Provides a mechanism for releasing unmanaged resources.To browse the .NET Framework source code for t...
Discovers the attributes of a field and provides access to field metadata.
static string GenerateManifest(Type eventSourceType, string assemblyPathToIncludeInManifest)
Returns a string of the XML manifest that is associated with the current event source.
BindingFlags
Specifies flags that control binding and the way in which the search for members and types is conduct...
virtual Type ReturnType
Gets the return type of this method.
abstract object [] GetCustomAttributes(bool inherit)
When overridden in a derived class, returns an array of all custom attributes applied to this member.
Provides access to custom attribute data for assemblies, modules, types, members and parameters that ...
Exception ConstructionException
[Supported in the .NET Framework 4.5.1 and later versions] Gets any exception that was thrown during ...
static IList< CustomAttributeData > GetCustomAttributes(MemberInfo target)
Returns a list of T:System.Reflection.CustomAttributeData objects representing data about the attribu...
Guid Guid
The unique identifier for the event source.
virtual void Dispose(bool disposing)
Releases the unmanaged resources used by the T:System.Diagnostics.Tracing.EventSource class and optio...
EventKeywords Keywords
Gets or sets the keywords applied to the event. If this property is not set, the event’s keywords wil...
Exposes the enumerator, which supports a simple iteration over a collection of a specified type....
The exception that is thrown when an error occurs during event tracing for Windows (ETW).
static Delegate Remove(Delegate source, Delegate value)
Removes the last occurrence of the invocation list of a delegate from the invocation list of another ...
static Delegate Combine(Delegate a, Delegate b)
Concatenates the invocation lists of two delegates.
Represents a resource manager that provides convenient access to culture-specific resources at run ti...
bool IsStatic
Gets a value indicating whether the method is static.
A type representing a date and time value.
EventSource()
Creates a new instance of the T:System.Diagnostics.Tracing.EventSource class.
static IEnumerable< EventSource > GetSources()
Gets a snapshot of all the event sources for the application domain.
static CultureInfo CurrentUICulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the current user interface...
Cer
Specifies a method's behavior when called within a constrained execution region.
Represents a weak reference, which references an object while still allowing that object to be reclai...
static Encoding BigEndianUnicode
Gets an encoding for the UTF-16 format that uses the big endian byte order.
unsafe void WriteEvent(int eventId, long arg1)
Writes an event by using the provided event identifier and 64-bit integer argument.
EventLevel
Identifies the level of an event.
void Add(T item)
Adds an object to the end of the T:System.Collections.Generic.List`1.
override string ToString()
Obtains a string representation of the current event source instance.
EventLevel Level
Gets or sets the event level applied to the event.
bool TryGetValue(TKey key, out TValue value)
Gets the value associated with the specified key.
Provides information about, and means to manipulate, the current environment and platform....
Represents a globally unique identifier (GUID).To browse the .NET Framework source code for this type...
Type ReflectedType
Provides COM objects with version-independent access to the P:System.Reflection.MemberInfo....
static void SendCommand(EventSource eventSource, EventCommand command, IDictionary< string, string > commandArguments)
Sends a command to a specified event source.
unsafe void WriteEvent(int eventId, int arg1, string arg2)
Writes an event by using the provided event identifier and 32-bit integer and string arguments.
void WriteEvent(int eventId)
Writes an event by using the provided event identifier.
EventSourceSettings
Specifies configuration options for an event source.
unsafe void WriteEvent(int eventId, long arg1, byte[] arg2)
Writes the event data using the specified indentifier and 64-bit integer and byte array arguments.
static void SetCurrentThreadActivityId(Guid activityId)
[Supported in the .NET Framework 4.5.1 and later versions] Sets the activity ID on the current thread...
static int CompareExchange(ref int location1, int value, int comparand)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
An event that is published when an application starts a new transaction or activity....
Provides the arguments for the M:System.Diagnostics.Tracing.EventSource.OnEventCommand(System....
Opens the file if it exists and seeks to the end of the file, or creates a new file....
unsafe void WriteEventCore(int eventId, int eventDataCount, EventData *data)
Creates a new Overload:System.Diagnostics.Tracing.EventSource.WriteEvent overload by using the provid...
unsafe void WriteEvent(int eventId, string arg1, long arg2)
Writes an event by using the provided event identifier and arguments.
virtual void OnEventCommand(EventCommandEventArgs command)
Called when the current event source is updated by the controller.
A platform-specific type that is used to represent a pointer or a handle.
Provides the ability to create events for event tracing for Windows (ETW).
void Write(string eventName)
Writes an event without fields, but with the specified name and default options.
static void PrepareConstrainedRegions()
Designates a body of code as a constrained execution region (CER).
IntPtr DataPointer
Gets or sets the pointer to the data for the new Overload:System.Diagnostics.Tracing....
Represents a delegate, which is a data structure that refers to a static method or to a class instanc...
bool IsEnabled()
Determines whether the current event source is enabled.
Represents type declarations: class types, interface types, array types, value types,...
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
bool IsEnabled(EventLevel level, EventKeywords keywords, EventChannel channel)
Determines whether the current event source is enabled for events with the specified level,...
Provides a way to access a managed object from unmanaged memory.
Provides the event data for creating fast Overload:System.Diagnostics.Tracing.EventSource....
MethodImplOptions
Defines the details of how a method is implemented.
void AddRange(IEnumerable< T > collection)
Adds the elements of the specified collection to the end of the T:System.Collections....
Indicates that data in the pipe is transmitted and read as a stream of messages.
string Name
Gets or sets the name of the event source.
abstract string Name
Gets the name of the current member.
static bool TryParse(string input, out Guid result)
Converts the string representation of a GUID to the equivalent T:System.Guid structure.
object Value
Gets the value of the argument for a simple argument or for an element of an array argument; gets a c...
EventSource(EventSourceSettings settings, params string[] traits)
Initializes a new instance of the T:System.Diagnostics.Tracing.EventSource to be used with non-contra...
EventSource(EventSourceSettings settings)
Creates a new instance of the T:System.Diagnostics.Tracing.EventSource class with the specified confi...
virtual MethodBody GetMethodBody()
When overridden in a derived class, gets a T:System.Reflection.MethodBody object that provides access...
Controls the system garbage collector, a service that automatically reclaims unused memory.
Discovers the attributes of a property and provides access to property metadata.
The exception that is thrown when one of the arguments provided to a method is not valid.
void Free()
Releases a T:System.Runtime.InteropServices.GCHandle.
unsafe void WriteEvent(int eventId, string arg1, string arg2, string arg3)
Writes an event by using the provided event identifier and string arguments.
static unsafe string PtrToStringUni(IntPtr ptr, int len)
Allocates a managed T:System.String and copies a specified number of characters from an unmanaged Uni...
EventTags
Specifies the tracking of activity start and stop events. You should only use the lower 24 bits....
virtual ConstructorInfo Constructor
Gets a T:System.Reflection.ConstructorInfo object that represents the constructor that would have ini...
Attribute can be applied to an enumeration.
unsafe void WriteEvent(int eventId, string arg1, string arg2)
Writes an event by using the provided event identifier and string arguments.
unsafe void WriteEventWithRelatedActivityId(int eventId, Guid relatedActivityId, params object[] args)
[Supported in the .NET Framework 4.5.1 and later versions] Writes an event that indicates that the cu...
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
void WriteEvent(int eventId, params object[] args)
Writes an event by using the provided event identifier and array of arguments.
EventSource(string eventSourceName)
Creates a new instance of the T:System.Diagnostics.Tracing.EventSource class with the specified name.
unsafe void WriteEvent(int eventId, long arg1, long arg2, long arg3)
Writes an event by using the provided event identifier and 64-bit arguments.
virtual byte [] GetILAsByteArray()
Returns the MSIL for the method body, as an array of bytes.
EventTask
Defines the tasks that apply to events.
virtual Module Module
Gets the module in which the type that declares the member represented by the current T:System....
unsafe void WriteEvent(int eventId, byte[] arg1)
Writes an event by using the provided event identifier and byte array argument.
virtual object GetRawConstantValue()
Returns a literal value associated with the field by a compiler.
void Write(string eventName, EventSourceOptions options)
Writes an event without fields, but with the specified name and options.
CustomAttributeTypedArgument TypedValue
Gets a T:System.Reflection.CustomAttributeTypedArgument structure that can be used to obtain the type...
EventSourceSettings Settings
Gets the settings applied to this event source.
virtual Type ParameterType
Gets the Type of this parameter.
static Encoding UTF8
Gets an encoding for the UTF-8 format.
MemberInfo MemberInfo
Gets the attribute member that would be used to set the named argument.
virtual bool ReflectionOnly
Gets a T:System.Boolean value indicating whether this assembly was loaded into the reflection-only co...
unsafe void WriteEvent(int eventId, string arg1)
Writes an event by using the provided event identifier and string argument.
unsafe void WriteEvent(int eventId, string arg1, int arg2, int arg3)
Writes an event by using the provided event identifier and arguments.
Consistency
Specifies a reliability contract.
string Name
Provides COM objects with version-independent access to the P:System.Reflection.MemberInfo....
static readonly Guid Empty
A read-only instance of the T:System.Guid structure whose value is all zeros.
void Assert()
Declares that the calling code can access the resource protected by a permission demand through the c...
EventCommand
Describes the command (P:System.Diagnostics.Tracing.EventCommandEventArgs.Command property) that is p...
unsafe void WriteEvent(int eventId, int arg1, int arg2)
Writes an event by using the provided event identifier and 32-bit integer arguments.
Provides information about a specific culture (called a locale for unmanaged code development)....
virtual IList< CustomAttributeTypedArgument > ConstructorArguments
Gets the list of positional arguments specified for the attribute instance represented by the T:Syste...
bool IsEnabled(EventLevel level, EventKeywords keywords)
Determines whether the current event source that has the specified level and keyword is enabled.
static void Sleep(int millisecondsTimeout)
Suspends the current thread for the specified number of milliseconds.
static Guid GetGuid(Type eventSourceType)
Gets the unique identifier for this implementation of the event source.
int Size
Gets or sets the number of payload items in the new Overload:System.Diagnostics.Tracing....
string Guid
Gets or sets the event source identifier.
unsafe void WriteEvent(int eventId, int arg1, int arg2, int arg3)
Writes an event by using the provided event identifier and 32-bit integer arguments.
static void SetCurrentThreadActivityId(Guid activityId, out Guid oldActivityThatWillContinue)
[Supported in the .NET Framework 4.5.1 and later versions] Sets the activity ID on the current thread...
EventOpcode Opcode
Gets or sets the operation code to use for the specified event.
Controls access to non-public types and members through the N:System.Reflection APIs....
Provides atomic operations for variables that are shared by multiple threads.
unsafe void WriteEvent(int eventId, long arg1, long arg2)
Writes an event by using the provided event identifier and 64-bit arguments.
unsafe void WriteEvent(int eventId, int arg1)
Writes an event by using the provided event identifier and 32-bit integer argument.
EventHandler< EventCommandEventArgs > EventCommandExecuted
Occurs when a command comes from an event listener.
abstract ParameterInfo [] GetParameters()
When overridden in a derived class, gets the parameters of the specified method or constructor.
EventChannel
Specifies the event log channel for the event.
Represents an asynchronous operation that can return a value.
Provides a set of static methods and properties that provide support for compilers....
static Guid CurrentThreadActivityId
[Supported in the .NET Framework 4.5.1 and later versions] Gets the activity ID of the current thread...
Creates and controls a thread, sets its priority, and gets its status.