wasSharpNET – Diff between revs 19 and 20
?pathlinks?
Rev 19 | Rev 20 | |||
---|---|---|---|---|
Line 13... | Line 13... | |||
13 | |
13 | |
|
14 | namespace wasSharpNET.Diagnostics |
14 | namespace wasSharpNET.Diagnostics |
|
15 | { |
15 | { |
|
16 | public static class ExceptionExtensions |
16 | public static class ExceptionExtensions |
|
17 | { |
17 | { |
|
18 | public static string PrettyPrint(this Exception x) |
18 | public static string PrettyPrint(this Exception ex) |
|
- | 19 | { |
||
- | 20 | if(ex == null) |
||
- | 21 | return string.Empty; |
||
19 | { |
22 | |
|
20 | var st = new StackTrace(x, true); |
23 | var st = new StackTrace(ex, true); |
|
- | 24 | var frames = st.GetFrames(); |
||
- | 25 | if (frames == null) |
||
Line 21... | Line 26... | |||
21 | var frames = st.GetFrames(); |
26 | return string.Empty; |
|
22 | |
27 | |
|
Line 23... | Line -... | |||
23 | StringBuilder sb = new StringBuilder(); |
- | ||
24 | sb.Append(Enumerable.Repeat('-', 75).ToArray()); |
28 | var sb = new StringBuilder(); |
|
25 | |
29 | sb.Append(Environment.NewLine); |
|
26 | int indent = 0; |
30 | |
|
- | 31 | foreach (var frame in frames) |
||
27 | foreach (var frame in frames) |
32 | { |
|
Line 28... | Line 33... | |||
28 | { |
33 | var fileName = frame?.GetFileName(); |
|
- | 34 | if (string.IsNullOrEmpty(fileName)) |
||
- | 35 | continue; |
||
29 | if (frame.GetFileLineNumber() < 1) |
36 | |
|
30 | continue; |
37 | sb.Append(Enumerable |
|
31 | |
38 | .Repeat('-', System.Console.WindowWidth) |
|
32 | sb.Append(Enumerable.Repeat(' ', indent).ToArray()); |
- | ||
33 | sb.Append(@" -> "); |
- | ||
34 | sb.Append("File: "); |
- | ||
35 | sb.Append(string.Join( |
- | ||
36 | Path.DirectorySeparatorChar.ToString(), |
- | ||
37 | frame.GetFileName() |
- | ||
38 | .Split(Path.DirectorySeparatorChar) |
- | ||
39 | .Reverse() |
- | ||
40 | .Take(2) |
39 | .Concat(Environment.NewLine) |
|
41 | .Reverse() |
40 | .ToArray()); |
|
42 | ) |
41 | sb.Append("File: "); |
|
43 | ); |
42 | sb.Append(fileName); |
|
44 | sb.Append(@" Method: "); |
43 | sb.Append(@" Method: "); |
|
45 | sb.Append(frame.GetMethod().Name); |
44 | sb.Append(frame.GetMethod().Name); |
|
46 | sb.Append(@" Line and Column : "); |
45 | sb.Append(@" Line and Column : "); |
|
47 | sb.Append(frame.GetFileLineNumber()); |
- | ||
48 | sb.Append(@":"); |
- | ||
49 | sb.Append(frame.GetFileColumnNumber()); |
46 | sb.Append(frame.GetFileLineNumber()); |
|
Line 50... | Line 47... | |||
50 | sb.Append(Environment.NewLine); |
47 | sb.Append(@":"); |
|
- | 48 | sb.Append(frame.GetFileColumnNumber()); |
||
- | 49 | sb.Append(Environment.NewLine); |
||
- | 50 | } |
||
51 | |
51 | |
|
52 | indent += 1; |
52 | sb.Append(Enumerable |
|
- | 53 | .Repeat('-', System.Console.WindowWidth) |
||
- | 54 | .Concat(Environment.NewLine) |
||
- | 55 | .ToArray()); |
||
- | 56 | sb.Append(ex); |
||
Line 53... | Line 57... | |||
53 | } |
57 | sb.Append(Environment.NewLine); |
|
54 | |
58 | sb.Append(Enumerable |
|
55 | sb.Append(Enumerable.Repeat('-', 75).ToArray()); |
59 | .Repeat('-', System.Console.WindowWidth) |
|
56 | sb.Append(x); |
60 | .Concat(Environment.NewLine) |