wasSharpNET – Diff between revs 16 and 17
?pathlinks?
Rev 16 | Rev 17 | |||
---|---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////// |
1 | /////////////////////////////////////////////////////////////////////////// |
|
2 | // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 // |
2 | // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 // |
|
3 | // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
3 | // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
|
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
|
5 | /////////////////////////////////////////////////////////////////////////// |
5 | /////////////////////////////////////////////////////////////////////////// |
|
6 | // Based on Oguzhan KIRCALI & CDspace @ https://stackoverflow.com/questions/4272579/how-to-print-full-stack-trace-in-exception |
6 | // Based on Oguzhan KIRCALI & CDspace @ https://stackoverflow.com/questions/4272579/how-to-print-full-stack-trace-in-exception |
|
7 | |
7 | |
|
8 | using System; |
8 | using System; |
|
9 | using System.Diagnostics; |
9 | using System.Diagnostics; |
|
10 | using System.Linq; |
10 | using System.Linq; |
|
11 | using System.Text; |
11 | using System.Text; |
|
12 | |
12 | |
|
13 | namespace wasSharpNET.Diagnostics |
13 | namespace wasSharpNET.Diagnostics |
|
14 | { |
14 | { |
|
15 | public static class ExceptionExtensions |
15 | public static class ExceptionExtensions |
|
16 | { |
16 | { |
|
17 | public static string PrettyPrint(this Exception x) |
17 | public static string PrettyPrint(this Exception x) |
|
18 | { |
18 | { |
|
19 | var st = new StackTrace(x, true); |
19 | var st = new StackTrace(x, true); |
|
20 | var frames = st.GetFrames(); |
20 | var frames = st.GetFrames(); |
|
21 | |
21 | |
|
22 | StringBuilder sb = new StringBuilder(); |
22 | StringBuilder sb = new StringBuilder(); |
|
23 | sb.Append(Enumerable.Repeat("-", 75)); |
23 | sb.Append(Enumerable.Repeat("-", 75)); |
|
24 | |
24 | |
|
25 | int indent = 0; |
25 | int indent = 0; |
|
26 | foreach (var frame in frames) |
26 | foreach (var frame in frames) |
|
27 | { |
27 | { |
|
28 | if (frame.GetFileLineNumber() < 1) |
28 | if (frame.GetFileLineNumber() < 1) |
|
29 | continue; |
29 | continue; |
|
30 | |
30 | |
|
31 | sb.Append(Enumerable.Repeat(" ", indent)); |
31 | sb.Append(Enumerable.Repeat(" ", indent)); |
|
32 | sb.Append(@" -> "); |
32 | sb.Append(@" -> "); |
|
33 | sb.Append("File: "); |
33 | sb.Append("File: "); |
|
34 | sb.Append(frame.GetFileName()); |
34 | sb.Append(string.Join(@"/", frame.GetFileName().Split('/').Reverse().Take(2).Reverse())); |
|
35 | sb.Append(@" Method: "); |
35 | sb.Append(@" Method: "); |
|
36 | sb.Append(frame.GetMethod().Name); |
36 | sb.Append(frame.GetMethod().Name); |
|
37 | sb.Append(@" Line and Column : "); |
37 | sb.Append(@" Line and Column : "); |
|
38 | sb.Append(frame.GetFileLineNumber()); |
38 | sb.Append(frame.GetFileLineNumber()); |
|
39 | sb.Append(@":"); |
39 | sb.Append(@":"); |
|
40 | sb.Append(frame.GetFileColumnNumber()); |
40 | sb.Append(frame.GetFileColumnNumber()); |
|
41 | sb.Append(@"\n"); |
41 | sb.Append(Environment.NewLine); |
|
42 | |
42 | |
|
43 | indent += 4; |
43 | indent += 4; |
|
44 | } |
44 | } |
|
45 | |
45 | |
|
46 | sb.Append(Enumerable.Repeat("-", 75)); |
46 | sb.Append(Enumerable.Repeat("-", 75)); |
|
47 | sb.Append(x); |
47 | sb.Append(x); |
|
48 | sb.Append(Enumerable.Repeat("-", 75)); |
48 | sb.Append(Enumerable.Repeat("-", 75)); |
|
49 | |
49 | |
|
50 | return sb.ToString(); |
50 | return sb.ToString(); |
|
51 | } |
51 | } |
|
52 | } |
52 | } |
|
53 | } |
53 | } |
|
54 | |
54 | |