protected internal bool WriteEvent(ref EventDescriptor eventDescriptor, int dataCount, IntPtr data) { uint num = 0; Guid activityId = DiagnosticsEventProvider.GetActivityId(); DiagnosticsEventProvider.SetActivityId(ref activityId); num = UnsafeNativeMethods.EventWrite(this.traceRegistrationHandle, ref eventDescriptor, (uint)dataCount, (void *)data); if (num == 0) { return(true); } DiagnosticsEventProvider.SetLastError((int)num); return(false); }
public unsafe bool WriteEvent(ref EventDescriptor eventDescriptor, string data) { UnsafeNativeMethods.EventData length = new UnsafeNativeMethods.EventData(); uint num = 0; data = data ?? string.Empty; if (this.IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords)) { if (data.Length > 32724) { DiagnosticsEventProvider.errorCode = DiagnosticsEventProvider.WriteEventErrorCode.EventTooBig; return(false); } Guid activityId = DiagnosticsEventProvider.GetActivityId(); DiagnosticsEventProvider.SetActivityId(ref activityId); length.Size = (uint)((data.Length + 1) * 2); length.Reserved = 0; fixed(string str = data) { string *offsetToStringData = &str; if (offsetToStringData != null) { offsetToStringData = offsetToStringData + RuntimeHelpers.OffsetToStringData; } length.DataPointer = (ulong)((char *)offsetToStringData); num = UnsafeNativeMethods.EventWrite(this.traceRegistrationHandle, ref eventDescriptor, 1, ref length); } } if (num == 0) { return(true); } DiagnosticsEventProvider.SetLastError((int)num); return(false); }
public unsafe bool WriteEvent(ref EventDescriptor eventDescriptor, params object[] eventPayload) { UnsafeNativeMethods.EventData eventDatum = new UnsafeNativeMethods.EventData(); uint num = 0; if (this.IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords)) { int length = 0; Guid activityId = DiagnosticsEventProvider.GetActivityId(); DiagnosticsEventProvider.SetActivityId(ref activityId); if (eventPayload == null || (int)eventPayload.Length == 0 || (int)eventPayload.Length == 1) { string str = null; byte * numPointer = stackalloc byte[16]; eventDatum.Size = 0; if (eventPayload != null && (int)eventPayload.Length != 0) { str = DiagnosticsEventProvider.EncodeObject(ref eventPayload[0], ref eventDatum, numPointer); length = 1; } if (eventDatum.Size > 65482) { DiagnosticsEventProvider.errorCode = DiagnosticsEventProvider.WriteEventErrorCode.EventTooBig; return(false); } if (str == null) { num = (length != 0 ? UnsafeNativeMethods.EventWrite(this.traceRegistrationHandle, ref eventDescriptor, (uint)length, ref eventDatum) : UnsafeNativeMethods.EventWrite(this.traceRegistrationHandle, ref eventDescriptor, 0, 0)); } else { fixed(string str1 = str) { string *offsetToStringData = &str1; if (offsetToStringData != null) { offsetToStringData = offsetToStringData + RuntimeHelpers.OffsetToStringData; } eventDatum.DataPointer = (ulong)((char *)offsetToStringData); num = UnsafeNativeMethods.EventWrite(this.traceRegistrationHandle, ref eventDescriptor, (uint)length, ref eventDatum); } } } else { length = (int)eventPayload.Length; if (length > 32) { throw Fx.Exception.AsError(new ArgumentOutOfRangeException("eventPayload", SRCore.EtwMaxNumberArgumentsExceeded(32)), null); } uint size = 0; int num1 = 0; int[] numArray = new int[8]; string[] strArrays = new string[8]; UnsafeNativeMethods.EventData *eventDataPointer = stackalloc UnsafeNativeMethods.EventData[checked (length * sizeof(UnsafeNativeMethods.EventData))]; UnsafeNativeMethods.EventData *eventDataPointer1 = eventDataPointer; byte *numPointer1 = stackalloc byte[16 * length]; for (int i = 0; i < (int)eventPayload.Length; i++) { if (eventPayload[i] != null) { string str2 = DiagnosticsEventProvider.EncodeObject(ref eventPayload[i], eventDataPointer1, numPointer1); numPointer1 = numPointer1 + 16; size = size + (*eventDataPointer1).Size; eventDataPointer1 = eventDataPointer1 + sizeof(UnsafeNativeMethods.EventData); if (str2 != null) { if (num1 >= 8) { throw Fx.Exception.AsError(new ArgumentOutOfRangeException("eventPayload", SRCore.EtwAPIMaxStringCountExceeded(8)), null); } strArrays[num1] = str2; numArray[num1] = i; num1++; } } } if (size > 65482) { DiagnosticsEventProvider.errorCode = DiagnosticsEventProvider.WriteEventErrorCode.EventTooBig; return(false); } fixed(string str3 = strArrays[0]) { string *strPointers = &str3; if (strPointers != null) { strPointers = strPointers + RuntimeHelpers.OffsetToStringData; } char *chrPointer = (char *)strPointers; fixed(string str4 = strArrays[1]) { string *offsetToStringData1 = &str4; if (offsetToStringData1 != null) { offsetToStringData1 = offsetToStringData1 + RuntimeHelpers.OffsetToStringData; } char *chrPointer1 = (char *)offsetToStringData1; fixed(string str5 = strArrays[2]) { string *strPointers1 = &str5; if (strPointers1 != null) { strPointers1 = strPointers1 + RuntimeHelpers.OffsetToStringData; } char *chrPointer2 = (char *)strPointers1; fixed(string str6 = strArrays[3]) { string *offsetToStringData2 = &str6; if (offsetToStringData2 != null) { offsetToStringData2 = offsetToStringData2 + RuntimeHelpers.OffsetToStringData; } char *chrPointer3 = (char *)offsetToStringData2; fixed(string str7 = strArrays[4]) { string *strPointers2 = &str7; if (strPointers2 != null) { strPointers2 = strPointers2 + RuntimeHelpers.OffsetToStringData; } char *chrPointer4 = (char *)strPointers2; fixed(string str8 = strArrays[5]) { string *offsetToStringData3 = &str8; if (offsetToStringData3 != null) { offsetToStringData3 = offsetToStringData3 + RuntimeHelpers.OffsetToStringData; } char *chrPointer5 = (char *)offsetToStringData3; fixed(string str9 = strArrays[6]) { string *strPointers3 = &str9; if (strPointers3 != null) { strPointers3 = strPointers3 + RuntimeHelpers.OffsetToStringData; } char *chrPointer6 = (char *)strPointers3; fixed(string str10 = strArrays[7]) { string *offsetToStringData4 = &str10; if (offsetToStringData4 != null) { offsetToStringData4 = offsetToStringData4 + RuntimeHelpers.OffsetToStringData; } char *chrPointer7 = (char *)offsetToStringData4; eventDataPointer1 = eventDataPointer; if (strArrays[0] != null) { (*(eventDataPointer1 + numArray[0] * sizeof(UnsafeNativeMethods.EventData))).DataPointer = (ulong)chrPointer; } if (strArrays[1] != null) { (*(eventDataPointer1 + numArray[1] * sizeof(UnsafeNativeMethods.EventData))).DataPointer = (ulong)chrPointer1; } if (strArrays[2] != null) { (*(eventDataPointer1 + numArray[2] * sizeof(UnsafeNativeMethods.EventData))).DataPointer = (ulong)chrPointer2; } if (strArrays[3] != null) { (*(eventDataPointer1 + numArray[3] * sizeof(UnsafeNativeMethods.EventData))).DataPointer = (ulong)chrPointer3; } if (strArrays[4] != null) { (*(eventDataPointer1 + numArray[4] * sizeof(UnsafeNativeMethods.EventData))).DataPointer = (ulong)chrPointer4; } if (strArrays[5] != null) { (*(eventDataPointer1 + numArray[5] * sizeof(UnsafeNativeMethods.EventData))).DataPointer = (ulong)chrPointer5; } if (strArrays[6] != null) { (*(eventDataPointer1 + numArray[6] * sizeof(UnsafeNativeMethods.EventData))).DataPointer = (ulong)chrPointer6; } if (strArrays[7] != null) { (*(eventDataPointer1 + numArray[7] * sizeof(UnsafeNativeMethods.EventData))).DataPointer = (ulong)chrPointer7; } num = UnsafeNativeMethods.EventWrite(this.traceRegistrationHandle, ref eventDescriptor, (uint)length, eventDataPointer); } } } } } } } } str4 = null; str5 = null; str6 = null; str7 = null; str8 = null; str9 = null; str10 = null; } } if (num == 0) { return(true); } DiagnosticsEventProvider.SetLastError((int)num); return(false); }