Beispiel #1
0
        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);
        }