Ejemplo n.º 1
0
 public override bool IsEnabled()
 {
     return(TraceCore.TraceCodeEventLogCriticalIsEnabled(this) ||
            TraceCore.TraceCodeEventLogVerboseIsEnabled(this) ||
            TraceCore.TraceCodeEventLogInfoIsEnabled(this) ||
            TraceCore.TraceCodeEventLogWarningIsEnabled(this) ||
            TraceCore.TraceCodeEventLogErrorIsEnabled(this));
 }
Ejemplo n.º 2
0
        public override void TraceEventLogEvent(TraceEventType type, TraceRecord traceRecord)
        {
            switch (type)
            {
            case TraceEventType.Critical:
                if (TraceCore.TraceCodeEventLogCriticalIsEnabled(this))
                {
                    TraceCore.TraceCodeEventLogCritical(this, traceRecord);
                }
                break;

            case TraceEventType.Verbose:
                if (TraceCore.TraceCodeEventLogVerboseIsEnabled(this))
                {
                    TraceCore.TraceCodeEventLogVerbose(this, traceRecord);
                }
                break;

            case TraceEventType.Information:
                if (TraceCore.TraceCodeEventLogInfoIsEnabled(this))
                {
                    TraceCore.TraceCodeEventLogInfo(this, traceRecord);
                }
                break;

            case TraceEventType.Warning:
                if (TraceCore.TraceCodeEventLogWarningIsEnabled(this))
                {
                    TraceCore.TraceCodeEventLogWarning(this, traceRecord);
                }
                break;

            case TraceEventType.Error:
                if (TraceCore.TraceCodeEventLogErrorIsEnabled(this))
                {
                    TraceCore.TraceCodeEventLogError(this, traceRecord);
                }
                break;
            }
        }
Ejemplo n.º 3
0
        public void UnsafeLogEvent(TraceEventType type, ushort eventLogCategory, uint eventId, bool shouldTrace, params string[] values)
        {
            if (EventLogger.logCountForPT < 5)
            {
                try
                {
                    int      length    = 0;
                    string[] strArrays = new string[(int)values.Length + 2];
                    for (int i = 0; i < (int)values.Length; i++)
                    {
                        string str = values[i];
                        str          = (string.IsNullOrEmpty(str) ? string.Empty : EventLogger.NormalizeEventLogParameter(str));
                        strArrays[i] = str;
                        length       = length + str.Length + 1;
                    }
                    string str1 = EventLogger.NormalizeEventLogParameter(EventLogger.UnsafeGetProcessName());
                    strArrays[(int)strArrays.Length - 2] = str1;
                    length = length + str1.Length + 1;
                    string str2 = EventLogger.UnsafeGetProcessId().ToString(CultureInfo.InvariantCulture);
                    strArrays[(int)strArrays.Length - 1] = str2;
                    length = length + str2.Length + 1;
                    if (length > 25600)
                    {
                        int num = 25600 / (int)strArrays.Length - 1;
                        for (int j = 0; j < (int)strArrays.Length; j++)
                        {
                            if (strArrays[j].Length > num)
                            {
                                strArrays[j] = strArrays[j].Substring(0, num);
                            }
                        }
                    }
                    SecurityIdentifier user     = WindowsIdentity.GetCurrent().User;
                    byte[]             numArray = new byte[user.BinaryLength];
                    user.GetBinaryForm(numArray, 0);
                    IntPtr[]   intPtrArray   = new IntPtr[(int)strArrays.Length];
                    GCHandle   gCHandle      = new GCHandle();
                    GCHandle[] gCHandleArray = null;
                    try
                    {
                        gCHandle      = GCHandle.Alloc(intPtrArray, GCHandleType.Pinned);
                        gCHandleArray = new GCHandle[(int)strArrays.Length];
                        for (int k = 0; k < (int)strArrays.Length; k++)
                        {
                            gCHandleArray[k] = GCHandle.Alloc(strArrays[k], GCHandleType.Pinned);
                            intPtrArray[k]   = gCHandleArray[k].AddrOfPinnedObject();
                        }
                        this.UnsafeWriteEventLog(type, eventLogCategory, eventId, strArrays, numArray, gCHandle);
                    }
                    finally
                    {
                        if (gCHandle.AddrOfPinnedObject() != IntPtr.Zero)
                        {
                            gCHandle.Free();
                        }
                        if (gCHandleArray != null)
                        {
                            GCHandle[] gCHandleArray1 = gCHandleArray;
                            for (int l = 0; l < (int)gCHandleArray1.Length; l++)
                            {
                                gCHandleArray1[l].Free();
                            }
                        }
                    }
                    if (shouldTrace && this.diagnosticTrace != null && (TraceCore.TraceCodeEventLogCriticalIsEnabled(this.diagnosticTrace) || TraceCore.TraceCodeEventLogVerboseIsEnabled(this.diagnosticTrace) || TraceCore.TraceCodeEventLogInfoIsEnabled(this.diagnosticTrace) || TraceCore.TraceCodeEventLogWarningIsEnabled(this.diagnosticTrace) || TraceCore.TraceCodeEventLogErrorIsEnabled(this.diagnosticTrace)))
                    {
                        Dictionary <string, string> strs = new Dictionary <string, string>((int)strArrays.Length + 4);
                        strs["CategoryID.Name"]  = "EventLogCategory";
                        strs["CategoryID.Value"] = eventLogCategory.ToString(CultureInfo.InvariantCulture);
                        strs["InstanceID.Name"]  = "EventId";
                        strs["InstanceID.Value"] = eventId.ToString(CultureInfo.InvariantCulture);
                        for (int m = 0; m < (int)values.Length; m++)
                        {
                            strs.Add(string.Concat("Value", m.ToString(CultureInfo.InvariantCulture)), (values[m] == null ? string.Empty : DiagnosticTrace.XmlEncode(values[m])));
                        }
                        TraceRecord    dictionaryTraceRecord = new DictionaryTraceRecord(strs);
                        TraceEventType traceEventType        = type;
                        switch (traceEventType)
                        {
                        case TraceEventType.Critical:
                        {
                            TraceCore.TraceCodeEventLogCritical(this.diagnosticTrace, dictionaryTraceRecord);
                            break;
                        }

                        case TraceEventType.Error:
                        {
                            TraceCore.TraceCodeEventLogError(this.diagnosticTrace, dictionaryTraceRecord);
                            break;
                        }

                        case TraceEventType.Critical | TraceEventType.Error:
                        {
                            break;
                        }

                        case TraceEventType.Warning:
                        {
                            TraceCore.TraceCodeEventLogWarning(this.diagnosticTrace, dictionaryTraceRecord);
                            break;
                        }

                        default:
                        {
                            if (traceEventType == TraceEventType.Information)
                            {
                                TraceCore.TraceCodeEventLogInfo(this.diagnosticTrace, dictionaryTraceRecord);
                                break;
                            }
                            else if (traceEventType == TraceEventType.Verbose)
                            {
                                TraceCore.TraceCodeEventLogVerbose(this.diagnosticTrace, dictionaryTraceRecord);
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                        }
                    }
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                }
                if (this.isInPartialTrust)
                {
                    EventLogger.logCountForPT = EventLogger.logCountForPT + 1;
                }
            }
        }
Ejemplo n.º 4
0
        public void UnsafeLogEvent(TraceEventType type, ushort eventLogCategory, uint eventId, bool shouldTrace, params string[] values)
        {
            if (logCountForPT >= 5)
            {
                return;
            }
            try
            {
                int      num       = 0;
                string[] logValues = new string[values.Length + 2];
                for (int i = 0; i < values.Length; i++)
                {
                    string str = values[i];
                    if (!string.IsNullOrEmpty(str))
                    {
                        str = NormalizeEventLogParameter(str);
                    }
                    else
                    {
                        str = string.Empty;
                    }
                    logValues[i] = str;
                    num         += str.Length + 1;
                }
                string str2 = NormalizeEventLogParameter(this.UnsafeGetProcessName());
                logValues[logValues.Length - 2] = str2;
                num += str2.Length + 1;
                string str3 = this.UnsafeGetProcessId().ToString(CultureInfo.InvariantCulture);
                logValues[logValues.Length - 1] = str3;
                num += str3.Length + 1;
                if (num > 0x6400)
                {
                    int length = (0x6400 / logValues.Length) - 1;
                    for (int j = 0; j < logValues.Length; j++)
                    {
                        if (logValues[j].Length > length)
                        {
                            logValues[j] = logValues[j].Substring(0, length);
                        }
                    }
                }
                SecurityIdentifier user       = WindowsIdentity.GetCurrent().User;
                byte[]             binaryForm = new byte[user.BinaryLength];
                user.GetBinaryForm(binaryForm, 0);
                IntPtr[]   ptrArray          = new IntPtr[logValues.Length];
                GCHandle   stringsRootHandle = new GCHandle();
                GCHandle[] handleArray       = null;
                try
                {
                    stringsRootHandle = GCHandle.Alloc(ptrArray, GCHandleType.Pinned);
                    handleArray       = new GCHandle[logValues.Length];
                    for (int k = 0; k < logValues.Length; k++)
                    {
                        handleArray[k] = GCHandle.Alloc(logValues[k], GCHandleType.Pinned);
                        ptrArray[k]    = handleArray[k].AddrOfPinnedObject();
                    }
                    this.UnsafeWriteEventLog(type, eventLogCategory, eventId, logValues, binaryForm, stringsRootHandle);
                }
                finally
                {
                    if (stringsRootHandle.AddrOfPinnedObject() != IntPtr.Zero)
                    {
                        stringsRootHandle.Free();
                    }
                    if (handleArray != null)
                    {
                        foreach (GCHandle handle2 in handleArray)
                        {
                            handle2.Free();
                        }
                    }
                }
                if ((shouldTrace && (this.diagnosticTrace != null)) && ((TraceCore.TraceCodeEventLogCriticalIsEnabled(this.diagnosticTrace) || TraceCore.TraceCodeEventLogVerboseIsEnabled(this.diagnosticTrace)) || ((TraceCore.TraceCodeEventLogInfoIsEnabled(this.diagnosticTrace) || TraceCore.TraceCodeEventLogWarningIsEnabled(this.diagnosticTrace)) || TraceCore.TraceCodeEventLogErrorIsEnabled(this.diagnosticTrace))))
                {
                    Dictionary <string, string> dictionary = new Dictionary <string, string>(logValues.Length + 4);
                    dictionary["CategoryID.Name"]  = "EventLogCategory";
                    dictionary["CategoryID.Value"] = eventLogCategory.ToString(CultureInfo.InvariantCulture);
                    dictionary["InstanceID.Name"]  = "EventId";
                    dictionary["InstanceID.Value"] = eventId.ToString(CultureInfo.InvariantCulture);
                    for (int m = 0; m < values.Length; m++)
                    {
                        dictionary.Add("Value" + m.ToString(CultureInfo.InvariantCulture), (values[m] == null) ? string.Empty : DiagnosticTrace.XmlEncode(values[m]));
                    }
                    TraceRecord traceRecord = new DictionaryTraceRecord(dictionary);
                    switch (type)
                    {
                    case TraceEventType.Critical:
                        TraceCore.TraceCodeEventLogCritical(this.diagnosticTrace, traceRecord);
                        goto Label_035C;

                    case TraceEventType.Error:
                        TraceCore.TraceCodeEventLogError(this.diagnosticTrace, traceRecord);
                        goto Label_035C;

                    case (TraceEventType.Error | TraceEventType.Critical):
                        goto Label_035C;

                    case TraceEventType.Warning:
                        TraceCore.TraceCodeEventLogWarning(this.diagnosticTrace, traceRecord);
                        goto Label_035C;

                    case TraceEventType.Information:
                        TraceCore.TraceCodeEventLogInfo(this.diagnosticTrace, traceRecord);
                        goto Label_035C;

                    case TraceEventType.Verbose:
                        TraceCore.TraceCodeEventLogVerbose(this.diagnosticTrace, traceRecord);
                        goto Label_035C;
                    }
                }
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
            }
Label_035C:
            if (this.isInPartialTrust)
            {
                logCountForPT++;
            }
        }