示例#1
0
        protected bool WriteTransferEvent(ref EventDescriptor eventDescriptor, Guid relatedActivityId, int dataCount, IntPtr data)
        {
            uint num        = 0;
            Guid activityId = DiagnosticsEventProvider.GetActivityId();

            num = UnsafeNativeMethods.EventWriteTransfer(this.traceRegistrationHandle, ref eventDescriptor, ref activityId, ref relatedActivityId, (uint)dataCount, (void *)data);
            if (num == 0)
            {
                return(true);
            }
            DiagnosticsEventProvider.SetLastError((int)num);
            return(false);
        }
示例#2
0
        public unsafe bool WriteMessageEvent(string eventMessage, byte eventLevel, long eventKeywords)
        {
            int num = 0;

            if (eventMessage == null)
            {
                throw Fx.Exception.AsError(new ArgumentNullException("eventMessage"), null);
            }
            if (this.IsEnabled(eventLevel, eventKeywords))
            {
                if (eventMessage.Length > 32724)
                {
                    DiagnosticsEventProvider.errorCode = DiagnosticsEventProvider.WriteEventErrorCode.EventTooBig;
                    return(false);
                }

                fixed(string str = eventMessage)
                {
                    string *offsetToStringData = &str;

                    if (offsetToStringData != null)
                    {
                        offsetToStringData = offsetToStringData + RuntimeHelpers.OffsetToStringData;
                    }
                    char *chrPointer = (char *)offsetToStringData;

                    num = (int)UnsafeNativeMethods.EventWriteString(this.traceRegistrationHandle, eventLevel, eventKeywords, chrPointer);
                }

                if (num != 0)
                {
                    DiagnosticsEventProvider.SetLastError(num);
                    return(false);
                }
            }
            return(true);
        }
示例#3
0
        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);
        }
示例#4
0
        public unsafe bool WriteTransferEvent(ref EventDescriptor eventDescriptor, Guid relatedActivityId, params object[] eventPayload)
        {
            uint num = 0;

            if (this.IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords))
            {
                Guid activityId = DiagnosticsEventProvider.GetActivityId();
                if (eventPayload == null || (int)eventPayload.Length == 0)
                {
                    num = UnsafeNativeMethods.EventWriteTransfer(this.traceRegistrationHandle, ref eventDescriptor, ref activityId, ref relatedActivityId, 0, 0);
                }
                else
                {
                    int 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 *numPointer = stackalloc byte[16 * length];
                    for (int i = 0; i < (int)eventPayload.Length; i++)
                    {
                        if (eventPayload[i] != null)
                        {
                            string str = DiagnosticsEventProvider.EncodeObject(ref eventPayload[i], eventDataPointer1, numPointer);
                            numPointer        = numPointer + 16;
                            size              = size + (*eventDataPointer1).Size;
                            eventDataPointer1 = eventDataPointer1 + sizeof(UnsafeNativeMethods.EventData);
                            if (str != null)
                            {
                                if (num1 >= 8)
                                {
                                    throw Fx.Exception.AsError(new ArgumentOutOfRangeException("eventPayload", SRCore.EtwAPIMaxStringCountExceeded(8)), null);
                                }
                                strArrays[num1] = str;
                                numArray[num1]  = i;
                                num1++;
                            }
                        }
                    }
                    if (size > 65482)
                    {
                        DiagnosticsEventProvider.errorCode = DiagnosticsEventProvider.WriteEventErrorCode.EventTooBig;
                        return(false);
                    }

                    fixed(string str1 = strArrays[0])
                    {
                        string *offsetToStringData = &str1;

                        if (offsetToStringData != null)
                        {
                            offsetToStringData = offsetToStringData + RuntimeHelpers.OffsetToStringData;
                        }
                        char *chrPointer = (char *)offsetToStringData;

                        fixed(string str2 = strArrays[1])
                        {
                            string *strPointers = &str2;

                            if (strPointers != null)
                            {
                                strPointers = strPointers + RuntimeHelpers.OffsetToStringData;
                            }
                            char *chrPointer1 = (char *)strPointers;

                            fixed(string str3 = strArrays[2])
                            {
                                string *offsetToStringData1 = &str3;

                                if (offsetToStringData1 != null)
                                {
                                    offsetToStringData1 = offsetToStringData1 + RuntimeHelpers.OffsetToStringData;
                                }
                                char *chrPointer2 = (char *)offsetToStringData1;

                                fixed(string str4 = strArrays[3])
                                {
                                    string *strPointers1 = &str4;

                                    if (strPointers1 != null)
                                    {
                                        strPointers1 = strPointers1 + RuntimeHelpers.OffsetToStringData;
                                    }
                                    char *chrPointer3 = (char *)strPointers1;

                                    fixed(string str5 = strArrays[4])
                                    {
                                        string *offsetToStringData2 = &str5;

                                        if (offsetToStringData2 != null)
                                        {
                                            offsetToStringData2 = offsetToStringData2 + RuntimeHelpers.OffsetToStringData;
                                        }
                                        char *chrPointer4 = (char *)offsetToStringData2;

                                        fixed(string str6 = strArrays[5])
                                        {
                                            string *strPointers2 = &str6;

                                            if (strPointers2 != null)
                                            {
                                                strPointers2 = strPointers2 + RuntimeHelpers.OffsetToStringData;
                                            }
                                            char *chrPointer5 = (char *)strPointers2;

                                            fixed(string str7 = strArrays[6])
                                            {
                                                string *offsetToStringData3 = &str7;

                                                if (offsetToStringData3 != null)
                                                {
                                                    offsetToStringData3 = offsetToStringData3 + RuntimeHelpers.OffsetToStringData;
                                                }
                                                char *chrPointer6 = (char *)offsetToStringData3;

                                                fixed(string str8 = strArrays[7])
                                                {
                                                    string *strPointers3 = &str8;

                                                    if (strPointers3 != null)
                                                    {
                                                        strPointers3 = strPointers3 + RuntimeHelpers.OffsetToStringData;
                                                    }
                                                    char *chrPointer7 = (char *)strPointers3;

                                                    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.EventWriteTransfer(this.traceRegistrationHandle, ref eventDescriptor, ref activityId, ref relatedActivityId, (uint)length, eventDataPointer);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    str2 = null;
                    str3 = null;
                    str4 = null;
                    str5 = null;
                    str6 = null;
                    str7 = null;
                    str8 = null;
                }
            }
            if (num == 0)
            {
                return(true);
            }
            DiagnosticsEventProvider.SetLastError((int)num);
            return(false);
        }