| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Globalization; |
| | | 6 | | using System.Runtime.Serialization; |
| | | 7 | | using System.Text; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF |
| | | 10 | | { |
| | | 11 | | [DataContract(Namespace = "http://schemas.datacontract.org/2004/07/System.ServiceModel")] |
| | | 12 | | public class ExceptionDetail |
| | | 13 | | { |
| | 4 | 14 | | public ExceptionDetail(Exception exception) |
| | | 15 | | { |
| | 4 | 16 | | if (exception == null) |
| | | 17 | | { |
| | 0 | 18 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(exception)); |
| | | 19 | | } |
| | | 20 | | |
| | 4 | 21 | | HelpLink = exception.HelpLink; |
| | 4 | 22 | | Message = exception.Message; |
| | 4 | 23 | | StackTrace = exception.StackTrace; |
| | 4 | 24 | | Type = exception.GetType().ToString(); |
| | | 25 | | |
| | 4 | 26 | | if (exception.InnerException != null) |
| | | 27 | | { |
| | 0 | 28 | | InnerException = new ExceptionDetail(exception.InnerException); |
| | | 29 | | } |
| | 4 | 30 | | } |
| | | 31 | | |
| | | 32 | | [DataMember] |
| | 8 | 33 | | public string HelpLink { get; set; } |
| | | 34 | | |
| | | 35 | | [DataMember] |
| | 4 | 36 | | public ExceptionDetail InnerException { get; set; } |
| | | 37 | | |
| | | 38 | | [DataMember] |
| | 8 | 39 | | public string Message { get; set; } |
| | | 40 | | |
| | | 41 | | [DataMember] |
| | 8 | 42 | | public string StackTrace { get; set; } |
| | | 43 | | |
| | | 44 | | [DataMember] |
| | 8 | 45 | | public string Type { get; set; } |
| | | 46 | | |
| | | 47 | | public override string ToString() |
| | | 48 | | { |
| | 0 | 49 | | return string.Format(CultureInfo.InvariantCulture, "{0}\n{1}", SR.SFxExceptionDetailFormat, ToStringHelper(f |
| | | 50 | | } |
| | | 51 | | |
| | | 52 | | internal string ToStringHelper(bool isInner) |
| | | 53 | | { |
| | 0 | 54 | | StringBuilder sb = new StringBuilder(); |
| | 0 | 55 | | sb.AppendFormat("{0}: {1}", Type, Message); |
| | 0 | 56 | | if (InnerException != null) |
| | | 57 | | { |
| | 0 | 58 | | sb.AppendFormat(" ----> {0}", InnerException.ToStringHelper(true)); |
| | | 59 | | } |
| | | 60 | | else |
| | | 61 | | { |
| | 0 | 62 | | sb.Append("\n"); |
| | | 63 | | } |
| | 0 | 64 | | sb.Append(StackTrace); |
| | 0 | 65 | | if (isInner) |
| | | 66 | | { |
| | 0 | 67 | | sb.AppendFormat("\n {0}\n", SR.SFxExceptionDetailEndOfInner); |
| | | 68 | | } |
| | 0 | 69 | | return sb.ToString(); |
| | | 70 | | } |
| | | 71 | | } |
| | | 72 | | } |