コード例 #1
0
        public static EventLogger UnsafeCreateEventLogger(string eventLogSourceName, DiagnosticTrace diagnosticTrace)
        {
            EventLogger logger = new EventLogger();

            logger.SetLogSourceName(eventLogSourceName, diagnosticTrace);
            return(logger);
        }
コード例 #2
0
 internal static bool AppDomainUnloadIsEnabled(DiagnosticTrace trace)
 {
     if (!trace.ShouldTrace(TraceEventLevel.Informational))
     {
         return IsEtwEventEnabled(trace, 0);
     }
     return true;
 }
コード例 #3
0
 internal static bool HandledExceptionIsEnabled(DiagnosticTrace trace)
 {
     if (!trace.ShouldTrace(TraceEventLevel.Informational))
     {
         return IsEtwEventEnabled(trace, 1);
     }
     return true;
 }
 internal static bool BookmarkResumptionRecord(DiagnosticTrace trace, Guid InstanceId, long RecordNumber, long EventTime, string Name, Guid SubInstanceID, string OwnerActivityName, string OwnerActivityId, string OwnerActivityInstanceId, string OwnerActivityTypeName, string Annotations, string ProfileName, string reference)
 {
     bool flag = true;
     TracePayload payload = trace.GetSerializedPayload(null, null, null);
     if (IsEtwEventEnabled(trace, 2))
     {
         flag = WriteEtwEvent(trace, 2, InstanceId, RecordNumber, EventTime, Name, SubInstanceID, OwnerActivityName, OwnerActivityId, OwnerActivityInstanceId, OwnerActivityTypeName, Annotations, ProfileName, reference, payload.AppDomainFriendlyName);
     }
     return flag;
 }
 internal static bool ActivityStateRecord(DiagnosticTrace trace, Guid InstanceId, long RecordNumber, long EventTime, string State, string Name, string ActivityId, string ActivityInstanceId, string ActivityTypeName, string Arguments, string Variables, string Annotations, string ProfileName, string reference)
 {
     bool flag = true;
     TracePayload payload = trace.GetSerializedPayload(null, null, null);
     if (IsEtwEventEnabled(trace, 1))
     {
         flag = WriteEtwEvent(trace, 1, InstanceId, RecordNumber, EventTime, State, Name, ActivityId, ActivityInstanceId, ActivityTypeName, Arguments, Variables, Annotations, ProfileName, reference, payload.AppDomainFriendlyName);
     }
     return flag;
 }
 internal static bool CustomTrackingRecordError(DiagnosticTrace trace, Guid InstanceId, long RecordNumber, long EventTime, string Name, string ActivityName, string ActivityId, string ActivityInstanceId, string ActivityTypeName, string Data, string Annotations, string ProfileName, string reference)
 {
     bool flag = true;
     TracePayload payload = trace.GetSerializedPayload(null, null, null);
     if (IsEtwEventEnabled(trace, 6))
     {
         flag = WriteEtwEvent(trace, 6, InstanceId, RecordNumber, EventTime, Name, ActivityName, ActivityId, ActivityInstanceId, ActivityTypeName, Data, Annotations, ProfileName, reference, payload.AppDomainFriendlyName);
     }
     return flag;
 }
コード例 #7
0
 internal static void AppDomainUnload(DiagnosticTrace trace, string param0, string param1, string param2)
 {
     TracePayload payload = trace.GetSerializedPayload(null, null, null);
     if (IsEtwEventEnabled(trace, 0))
     {
         WriteEtwEvent(trace, 0, param0, param1, param2, payload.AppDomainFriendlyName);
     }
     if (trace.ShouldTraceToTraceSource(TraceEventLevel.Informational))
     {
         string description = string.Format(Culture, ResourceManager.GetString("AppDomainUnload", Culture), new object[] { param0, param1, param2 });
         WriteTraceSource(trace, 0, description, payload);
     }
 }
コード例 #8
0
 private static DiagnosticTrace InitializeTracing()
 {
     etwProviderId = DiagnosticTrace.DefaultEtwProviderId;
     DiagnosticTrace trace = new DiagnosticTrace("System.ServiceModel.Activation", etwProviderId);
     if (trace.EtwProvider != null)
     {
         trace.RefreshState = (Action) Delegate.Combine(trace.RefreshState, delegate {
             UpdateLevel();
         });
     }
     UpdateLevel(trace);
     return trace;
 }
コード例 #9
0
 internal static void HandledExceptionWarning(DiagnosticTrace trace, Exception exception)
 {
     TracePayload payload = trace.GetSerializedPayload(null, null, exception);
     if (IsEtwEventEnabled(trace, 11))
     {
         WriteEtwEvent(trace, 11, payload.SerializedException, payload.AppDomainFriendlyName);
     }
     if (trace.ShouldTraceToTraceSource(TraceEventLevel.Warning))
     {
         string description = string.Format(Culture, ResourceManager.GetString("HandledExceptionWarning", Culture), new object[0]);
         WriteTraceSource(trace, 11, description, payload);
     }
 }
コード例 #10
0
 public EventLogger(string eventLogSourceName, DiagnosticTrace diagnosticTrace)
 {
     try
     {
         this.diagnosticTrace = diagnosticTrace;
         if (canLogEvent)
         {
             this.SafeSetLogSourceName(eventLogSourceName);
         }
     }
     catch (SecurityException)
     {
         canLogEvent = false;
     }
 }
コード例 #11
0
 public EventLogger(string eventLogSourceName, DiagnosticTrace diagnosticTrace)
 {
     try
     {
         this.diagnosticTrace = diagnosticTrace;
         if (canLogEvent)
         {
             this.SafeSetLogSourceName(eventLogSourceName);
         }
     }
     catch (SecurityException)
     {
         canLogEvent = false;
     }
 }
 private void InitializeEtwTrackingProvider(Guid providerId)
 {
     this.diagnosticTrace = (DiagnosticTrace) diagnosticTraceCache[providerId];
     if (this.diagnosticTrace == null)
     {
         lock (diagnosticTraceCache)
         {
             this.diagnosticTrace = (DiagnosticTrace) diagnosticTraceCache[providerId];
             if (this.diagnosticTrace == null)
             {
                 this.diagnosticTrace = new DiagnosticTrace(null, providerId);
                 diagnosticTraceCache.Add(providerId, this.diagnosticTrace);
             }
         }
     }
     this.etwProviderId = providerId;
 }
コード例 #13
0
 private static void UpdateLevel(DiagnosticTrace trace)
 {
     tracingEnabled = trace.TracingEnabled;
     shouldTraceCriticalToTraceSource = trace.ShouldTraceToTraceSource(TraceEventLevel.Critical);
     shouldTraceErrorToTraceSource = trace.ShouldTraceToTraceSource(TraceEventLevel.Error);
     shouldTraceWarningToTraceSource = trace.ShouldTraceToTraceSource(TraceEventLevel.Warning);
     shouldTraceInformationToTraceSource = trace.ShouldTraceToTraceSource(TraceEventLevel.Informational);
     shouldTraceVerboseToTraceSource = trace.ShouldTraceToTraceSource(TraceEventLevel.Verbose);
     shouldTraceCritical = shouldTraceCriticalToTraceSource || trace.ShouldTraceToEtw(TraceEventLevel.Critical);
     shouldTraceError = shouldTraceErrorToTraceSource || trace.ShouldTraceToEtw(TraceEventLevel.Error);
     shouldTraceWarning = shouldTraceWarningToTraceSource || trace.ShouldTraceToEtw(TraceEventLevel.Warning);
     shouldTraceInformation = shouldTraceInformationToTraceSource || trace.ShouldTraceToEtw(TraceEventLevel.Informational);
     shouldTraceVerbose = shouldTraceVerboseToTraceSource || trace.ShouldTraceToEtw(TraceEventLevel.Verbose);
     UpdateEnabledEventsList();
 }
コード例 #14
0
 private static bool WriteEtwEvent(DiagnosticTrace trace, int eventIndex, string eventParam0, string eventParam1, string eventParam2, string eventParam3)
 {
     EnsureEventDescriptors();
     return trace.EtwProvider.WriteEvent(ref eventDescriptors[eventIndex], eventParam0, eventParam1, eventParam2, eventParam3);
 }
コード例 #15
0
 internal static bool UnhandledExceptionIsEnabled(DiagnosticTrace trace)
 {
     if (!trace.ShouldTrace(TraceEventLevel.Error))
     {
         return IsEtwEventEnabled(trace, 4);
     }
     return true;
 }
コード例 #16
0
 internal static bool TraceCodeEventLogWarningIsEnabled(DiagnosticTrace trace)
 {
     if (!trace.ShouldTrace(TraceEventLevel.Warning))
     {
         return IsEtwEventEnabled(trace, 10);
     }
     return true;
 }
コード例 #17
0
 protected string XmlEncode(string text)
 {
     return(DiagnosticTrace.XmlEncode(text));
 }
コード例 #18
0
 public static EventLogger UnsafeCreateEventLogger(string eventLogSourceName, DiagnosticTrace diagnosticTrace)
 {
     EventLogger logger = new EventLogger();
     logger.SetLogSourceName(eventLogSourceName, diagnosticTrace);
     return logger;
 }
コード例 #19
0
 private static void WriteTraceSource(DiagnosticTrace trace, int eventIndex, string description, TracePayload payload)
 {
     EnsureEventDescriptors();
     trace.WriteTraceSource(ref eventDescriptors[eventIndex], description, payload);
 }
コード例 #20
0
 internal static void MaxInstancesExceeded(DiagnosticTrace trace, int limit)
 {
     TracePayload payload = trace.GetSerializedPayload(null, null, null);
     if (IsEtwEventEnabled(trace, 5))
     {
         WriteEtwEvent(trace, 5, limit, payload.AppDomainFriendlyName);
     }
     if (trace.ShouldTraceToTraceSource(TraceEventLevel.Warning))
     {
         string description = string.Format(Culture, ResourceManager.GetString("MaxInstancesExceeded", Culture), new object[] { limit });
         WriteTraceSource(trace, 5, description, payload);
     }
 }
コード例 #21
0
 internal static bool TraceCodeEventLogCriticalIsEnabled(DiagnosticTrace trace)
 {
     if (!trace.ShouldTrace(TraceEventLevel.Critical))
     {
         return IsEtwEventEnabled(trace, 6);
     }
     return true;
 }
コード例 #22
0
 internal static void ThrowingException(DiagnosticTrace trace, string param0, Exception exception)
 {
     TracePayload payload = trace.GetSerializedPayload(null, null, exception);
     if (IsEtwEventEnabled(trace, 3))
     {
         WriteEtwEvent(trace, 3, param0, payload.SerializedException, payload.AppDomainFriendlyName);
     }
     if (trace.ShouldTraceToTraceSource(TraceEventLevel.Error))
     {
         string description = string.Format(Culture, ResourceManager.GetString("ThrowingException", Culture), new object[] { param0 });
         WriteTraceSource(trace, 3, description, payload);
     }
 }
コード例 #23
0
 internal static bool ShipAssertExceptionMessageIsEnabled(DiagnosticTrace trace)
 {
     if (!trace.ShouldTrace(TraceEventLevel.Error))
     {
         return IsEtwEventEnabled(trace, 2);
     }
     return true;
 }
コード例 #24
0
 internal static void ShipAssertExceptionMessage(DiagnosticTrace trace, string param0)
 {
     TracePayload payload = trace.GetSerializedPayload(null, null, null);
     if (IsEtwEventEnabled(trace, 2))
     {
         WriteEtwEvent(trace, 2, param0, payload.AppDomainFriendlyName);
     }
     if (trace.ShouldTraceToTraceSource(TraceEventLevel.Error))
     {
         string description = string.Format(Culture, ResourceManager.GetString("ShipAssertExceptionMessage", Culture), new object[] { param0 });
         WriteTraceSource(trace, 2, description, payload);
     }
 }
コード例 #25
0
 internal static bool MaxInstancesExceededIsEnabled(DiagnosticTrace trace)
 {
     if (!trace.ShouldTrace(TraceEventLevel.Warning))
     {
         return IsEtwEventEnabled(trace, 5);
     }
     return true;
 }
コード例 #26
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++;
            }
        }
 internal static bool CancelRequestedRecordIsEnabled(DiagnosticTrace trace)
 {
     return IsEtwEventEnabled(trace, 3);
 }
コード例 #28
0
 private static bool IsEtwEventEnabled(DiagnosticTrace trace, int eventIndex)
 {
     EnsureEventDescriptors();
     return trace.IsEtwEventEnabled(ref eventDescriptors[eventIndex]);
 }
コード例 #29
0
 internal static bool TraceCodeEventLogInfoIsEnabled(DiagnosticTrace trace)
 {
     if (!trace.ShouldTrace(TraceEventLevel.Informational))
     {
         return IsEtwEventEnabled(trace, 8);
     }
     return true;
 }
コード例 #30
0
 private void SetLogSourceName(string eventLogSourceName, DiagnosticTrace diagnosticTrace)
 {
     this.eventLogSourceName = eventLogSourceName;
     this.diagnosticTrace = diagnosticTrace;
 }
コード例 #31
0
 internal static bool TraceCodeEventLogVerboseIsEnabled(DiagnosticTrace trace)
 {
     if (!trace.ShouldTrace(TraceEventLevel.Verbose))
     {
         return IsEtwEventEnabled(trace, 9);
     }
     return true;
 }
コード例 #32
0
 internal static void TraceCodeEventLogWarning(DiagnosticTrace trace, TraceRecord traceRecord)
 {
     TracePayload payload = trace.GetSerializedPayload(null, traceRecord, null);
     if (IsEtwEventEnabled(trace, 10))
     {
         WriteEtwEvent(trace, 10, payload.ExtendedData, payload.AppDomainFriendlyName);
     }
     if (trace.ShouldTraceToTraceSource(TraceEventLevel.Warning))
     {
         string description = string.Format(Culture, ResourceManager.GetString("TraceCodeEventLogWarning", Culture), new object[0]);
         WriteTraceSource(trace, 10, description, payload);
     }
 }
 internal static bool CustomTrackingRecordErrorIsEnabled(DiagnosticTrace trace)
 {
     return IsEtwEventEnabled(trace, 6);
 }
コード例 #34
0
 internal static bool TraceCodeEventLogErrorIsEnabled(DiagnosticTrace trace)
 {
     if (!trace.ShouldTrace(TraceEventLevel.Error))
     {
         return IsEtwEventEnabled(trace, 7);
     }
     return true;
 }
コード例 #35
0
 private void SetLogSourceName(string eventLogSourceName, DiagnosticTrace diagnosticTrace)
 {
     this.eventLogSourceName = eventLogSourceName;
     this.diagnosticTrace    = diagnosticTrace;
 }