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