public override void TraceEventLogEvent(TraceEventType type, TraceRecord traceRecord) { TraceEvent(type, DiagnosticsTraceCode.EventLog, LegacyDiagnosticTrace.GenerateMsdnTraceCode("System.ServiceModel.Diagnostics", "EventLog"), TraceSR.GetString(TraceSR.TraceCodeEventLog), traceRecord, null, null); }
internal ExceptionUtility(string name, string eventSourceName, object diagnosticTrace, object exceptionTrace) { this.diagnosticTrace = (LegacyDiagnosticTrace)diagnosticTrace; this.exceptionTrace = (ExceptionTrace)exceptionTrace; this.name = name; this.eventSourceName = eventSourceName; }
protected override void OnShutdownTracing() { if (null != this.TraceSource) { #pragma warning disable 618 if (this.Level != SourceLevels.Off) { if (this.ShouldTrace(TraceEventType.Information)) #pragma warning restore 618 { Dictionary <string, string> values = new Dictionary <string, string>(3); values["AppDomain.FriendlyName"] = AppDomain.CurrentDomain.FriendlyName; values["ProcessName"] = DiagnosticTraceBase.ProcessName; values["ProcessId"] = DiagnosticTraceBase.ProcessId.ToString(CultureInfo.CurrentCulture); this.TraceEvent(TraceEventType.Information, DiagnosticsTraceCode.AppDomainUnload, LegacyDiagnosticTrace.GenerateMsdnTraceCode("System.ServiceModel.Diagnostics", "AppDomainUnload"), TraceSR.GetString(TraceSR.TraceCodeAppDomainUnload), new DictionaryTraceRecord(values), null, null); } this.TraceSource.Flush(); } } }
#pragma warning disable 56500 internal void TraceEvent(TraceEventType type, int code, string msdnTraceCode, string description, TraceRecord trace, Exception exception, object source) { #pragma warning disable 618 Fx.Assert(exception == null || type <= TraceEventType.Information, "Exceptions should be traced at Information or higher"); Fx.Assert(!string.IsNullOrEmpty(description), "All TraceCodes should have a description"); #pragma warning restore 618 TraceXPathNavigator navigator = null; try { #pragma warning disable 618 if (this.TraceSource != null && this.HaveListeners) #pragma warning restore 618 { try { BuildTrace(type, msdnTraceCode, description, trace, exception, source, out navigator); } catch (PlainXmlWriter.MaxSizeExceededException) { StringTraceRecord codeTraceRecord = new StringTraceRecord("TruncatedTraceId", msdnTraceCode); this.TraceEvent(type, DiagnosticsTraceCode.TraceTruncatedQuotaExceeded, LegacyDiagnosticTrace.GenerateMsdnTraceCode("System.ServiceModel.Diagnostics", "TraceTruncatedQuotaExceeded"), TraceSR.GetString(TraceSR.TraceCodeTraceTruncatedQuotaExceeded), codeTraceRecord, null, null); } this.TraceSource.TraceData(type, code, navigator); if (this.CalledShutdown) { this.TraceSource.Flush(); } // Must have been a successful trace. this.LastFailure = DateTime.MinValue; } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } LogTraceFailure(navigator == null ? string.Empty : navigator.ToString(), e); } }
internal void DiagnosticTraceHandledException(Exception exception, TraceEventType eventType) { #pragma warning disable 618 bool shouldTrace = (this.diagnosticTrace != null && this.diagnosticTrace.ShouldTrace(eventType)); #pragma warning restore 618 if (shouldTrace) { using (ExceptionUtility.useStaticActivityId ? Activity.CreateActivity(ExceptionUtility.activityId) : null) { this.diagnosticTrace.TraceEvent(eventType, DiagnosticsTraceCode.TraceHandledException, LegacyDiagnosticTrace.GenerateMsdnTraceCode("System.ServiceModel.Diagnostics", "TraceHandledException"), TraceSR.GetString(TraceSR.TraceHandledException), null, exception, null); } } }
internal Exception ThrowHelper(Exception exception, TraceEventType eventType, TraceRecord extendedData) { #pragma warning disable 618 bool shouldTrace = (this.diagnosticTrace != null && this.diagnosticTrace.ShouldTrace(eventType)); #pragma warning restore 618 if (shouldTrace) { using (ExceptionUtility.useStaticActivityId ? Activity.CreateActivity(ExceptionUtility.activityId) : null) { this.diagnosticTrace.TraceEvent(eventType, DiagnosticsTraceCode.ThrowingException, LegacyDiagnosticTrace.GenerateMsdnTraceCode("System.ServiceModel.Diagnostics", "ThrowingException"), TraceSR.GetString(TraceSR.ThrowingException), extendedData, exception, null); } IDictionary data = exception.Data; if (data != null && !data.IsReadOnly && !data.IsFixedSize) { object existingString = data[ExceptionStackAsStringKey]; string stackString = existingString == null ? "" : existingString as string; if (stackString != null) { string stack = exception.StackTrace; if (!string.IsNullOrEmpty(stack)) { stackString = string.Concat(stackString, stackString.Length == 0 ? "" : Environment.NewLine, "throw", Environment.NewLine, stack, Environment.NewLine, "catch", Environment.NewLine); data[ExceptionStackAsStringKey] = stackString; } } } } // Trace using ETW as well. exceptionTrace.TraceEtwException(exception, eventType); return(exception); }