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