public unsafe bool WriteEvent(ref EventDescriptor eventDescriptor, EventTraceActivity eventTraceActivity, string data) { uint num = 0; string str = data; string empty = str; if (str == null) { empty = string.Empty; } data = empty; if (this.IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords)) { if (data.Length <= 0x7fd4) { if (eventTraceActivity != null) { DiagnosticsEventProvider.SetActivityId(ref eventTraceActivity.ActivityId); } UnsafeNativeMethods.EventData length; length.Size = (data.Length + 1) * 2; length.Reserved = 0; fixed(string str1 = data) { string *strPointers = &str1; char * offsetToStringData = (char *)(&str1); if (&str1 != null) { offsetToStringData = (char *)(strPointers + RuntimeHelpers.OffsetToStringData); } length.DataPointer = (ulong)offsetToStringData; num = UnsafeNativeMethods.EventWrite(this.traceRegistrationHandle, ref eventDescriptor, 1, ref length); } } else { DiagnosticsEventProvider.errorCode = DiagnosticsEventProvider.WriteEventErrorCode.EventTooBig; return(false); } } if (num == 0) { return(true); } else { DiagnosticsEventProvider.SetLastError(num); return(false); } }
protected internal bool WriteEvent(ref EventDescriptor eventDescriptor, EventTraceActivity eventTraceActivity, int dataCount, IntPtr data) { if (eventTraceActivity != null) { DiagnosticsEventProvider.SetActivityId(ref eventTraceActivity.ActivityId); } uint num = UnsafeNativeMethods.EventWrite(this.traceRegistrationHandle, ref eventDescriptor, dataCount, (void *)data); if (num == 0) { return(true); } else { DiagnosticsEventProvider.SetLastError(num); return(false); } }
public unsafe bool WriteMessageEvent(EventTraceActivity eventTraceActivity, string eventMessage, byte eventLevel, long eventKeywords) { if (eventMessage != null) { if (eventTraceActivity != null) { DiagnosticsEventProvider.SetActivityId(ref eventTraceActivity.ActivityId); } if (this.IsEnabled(eventLevel, eventKeywords)) { if (eventMessage.Length <= 0x7fd4) { fixed(string str = eventMessage) { string *strPointers = &str; char * offsetToStringData = (char *)(&str); if (&str != null) { offsetToStringData = (char *)(strPointers + RuntimeHelpers.OffsetToStringData); } int num = UnsafeNativeMethods.EventWriteString(this.traceRegistrationHandle, eventLevel, eventKeywords, offsetToStringData); } } else { DiagnosticsEventProvider.errorCode = DiagnosticsEventProvider.WriteEventErrorCode.EventTooBig; return(false); } } return(true); } else { throw Fx.Exception.AsError(new ArgumentNullException("eventMessage")); } }
public unsafe bool WriteEvent(ref EventDescriptor eventDescriptor, EventTraceActivity eventTraceActivity, object[] eventPayload) { uint num = 0; if (this.IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords)) { int length = 0; if (eventTraceActivity != null) { DiagnosticsEventProvider.SetActivityId(ref eventTraceActivity.ActivityId); } if (eventPayload == null || (int)eventPayload.Length == 0 || (int)eventPayload.Length == 1) { string str = null; byte * numPointer = (byte *)16; UnsafeNativeMethods.EventData eventDatum; eventDatum.Size = 0; if (eventPayload != null && (int)eventPayload.Length != 0) { str = DiagnosticsEventProvider.EncodeObject(ref eventPayload[0], ref eventDatum, numPointer); length = 1; } if (eventDatum.Size <= 0xffca) { if (str == null) { if (length != 0) { num = UnsafeNativeMethods.EventWrite(this.traceRegistrationHandle, ref eventDescriptor, length, ref eventDatum); } else { num = UnsafeNativeMethods.EventWrite(this.traceRegistrationHandle, ref eventDescriptor, 0, 0); } } else { fixed(string str1 = str) { string *strPointers = &str1; char * offsetToStringData = (char *)(&str1); if (&str1 != null) { offsetToStringData = (char *)(strPointers + RuntimeHelpers.OffsetToStringData); } eventDatum.DataPointer = (ulong)offsetToStringData; num = UnsafeNativeMethods.EventWrite(this.traceRegistrationHandle, ref eventDescriptor, length, ref eventDatum); } } } else { DiagnosticsEventProvider.errorCode = DiagnosticsEventProvider.WriteEventErrorCode.EventTooBig; return(false); } } else { length = (int)eventPayload.Length; if (length <= 32) { uint size = 0; int num1 = 0; int[] numArray = new int[8]; string[] strArrays = new string[8]; UnsafeNativeMethods.EventData *eventDataPointer = (UnsafeNativeMethods.EventData *)length * sizeof(UnsafeNativeMethods.EventData); UnsafeNativeMethods.EventData *eventDataPointer1 = eventDataPointer; byte *numPointer1 = (byte *)16 * length; byte *numPointer2 = numPointer1; for (int i = 0; i < (int)eventPayload.Length; i++) { if (eventPayload[i] != null) { string str2 = DiagnosticsEventProvider.EncodeObject(ref eventPayload[i], eventDataPointer1, numPointer2); numPointer2 = numPointer2 + 16; size = size + (*(eventDataPointer1)).Size; eventDataPointer1 = (UnsafeNativeMethods.EventData *)(eventDataPointer1 + sizeof(UnsafeNativeMethods.EventData)); if (str2 != null) { if (num1 >= 8) { throw Fx.Exception.AsError(new ArgumentOutOfRangeException("eventPayload", InternalSR.EtwAPIMaxStringCountExceeded(8))); } else { strArrays[num1] = str2; numArray[num1] = i; num1++; } } } } if (size <= 0xffca) { fixed(string str3 = strArrays[0]) { string *strPointers1 = &str3; char * chrPointer = (char *)(&str3); if (&str3 != null) { chrPointer = (char *)(strPointers1 + RuntimeHelpers.OffsetToStringData); } char *chrPointer1 = chrPointer; fixed(string str4 = strArrays[1]) { string *strPointers2 = &str4; char * offsetToStringData1 = (char *)(&str4); if (&str4 != null) { offsetToStringData1 = (char *)(strPointers2 + RuntimeHelpers.OffsetToStringData); } char *chrPointer2 = offsetToStringData1; fixed(string str5 = strArrays[2]) { string *strPointers3 = &str5; char * offsetToStringData2 = (char *)(&str5); if (&str5 != null) { offsetToStringData2 = (char *)(strPointers3 + RuntimeHelpers.OffsetToStringData); } char *chrPointer3 = offsetToStringData2; fixed(string str6 = strArrays[3]) { string *strPointers4 = &str6; char * offsetToStringData3 = (char *)(&str6); if (&str6 != null) { offsetToStringData3 = (char *)(strPointers4 + RuntimeHelpers.OffsetToStringData); } char *chrPointer4 = offsetToStringData3; fixed(string str7 = strArrays[4]) { string *strPointers5 = &str7; char * offsetToStringData4 = (char *)(&str7); if (&str7 != null) { offsetToStringData4 = (char *)(strPointers5 + RuntimeHelpers.OffsetToStringData); } char *chrPointer5 = offsetToStringData4; fixed(string str8 = strArrays[5]) { string *strPointers6 = &str8; char * offsetToStringData5 = (char *)(&str8); if (&str8 != null) { offsetToStringData5 = (char *)(strPointers6 + RuntimeHelpers.OffsetToStringData); } char *chrPointer6 = offsetToStringData5; fixed(string str9 = strArrays[6]) { string *strPointers7 = &str9; char * offsetToStringData6 = (char *)(&str9); if (&str9 != null) { offsetToStringData6 = (char *)(strPointers7 + RuntimeHelpers.OffsetToStringData); } char *chrPointer7 = offsetToStringData6; fixed(string str10 = strArrays[7]) { string *strPointers8 = &str10; char * offsetToStringData7 = (char *)(&str10); if (&str10 != null) { offsetToStringData7 = (char *)(strPointers8 + RuntimeHelpers.OffsetToStringData); } char *chrPointer8 = offsetToStringData7; eventDataPointer1 = eventDataPointer; if (strArrays[0] != null) { (eventDataPointer1 + numArray[0] * sizeof(UnsafeNativeMethods.EventData)).DataPointer = (ulong)chrPointer1; } if (strArrays[1] != null) { (eventDataPointer1 + numArray[1] * sizeof(UnsafeNativeMethods.EventData)).DataPointer = (ulong)chrPointer2; } if (strArrays[2] != null) { (eventDataPointer1 + numArray[2] * sizeof(UnsafeNativeMethods.EventData)).DataPointer = (ulong)chrPointer3; } if (strArrays[3] != null) { (eventDataPointer1 + numArray[3] * sizeof(UnsafeNativeMethods.EventData)).DataPointer = (ulong)chrPointer4; } if (strArrays[4] != null) { (eventDataPointer1 + numArray[4] * sizeof(UnsafeNativeMethods.EventData)).DataPointer = (ulong)chrPointer5; } if (strArrays[5] != null) { (eventDataPointer1 + numArray[5] * sizeof(UnsafeNativeMethods.EventData)).DataPointer = (ulong)chrPointer6; } if (strArrays[6] != null) { (eventDataPointer1 + numArray[6] * sizeof(UnsafeNativeMethods.EventData)).DataPointer = (ulong)chrPointer7; } if (strArrays[7] != null) { (eventDataPointer1 + numArray[7] * sizeof(UnsafeNativeMethods.EventData)).DataPointer = (ulong)chrPointer8; } num = UnsafeNativeMethods.EventWrite(this.traceRegistrationHandle, ref eventDescriptor, length, eventDataPointer); } } } } } } } } } else { DiagnosticsEventProvider.errorCode = DiagnosticsEventProvider.WriteEventErrorCode.EventTooBig; return(false); } } else { throw Fx.Exception.AsError(new ArgumentOutOfRangeException("eventPayload", InternalSR.EtwMaxNumberArgumentsExceeded(32))); } } } if (num == 0) { return(true); } else { DiagnosticsEventProvider.SetLastError(num); return(false); } }