wasSharpNET – Diff between revs 18 and 19

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 18 Rev 19
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 using System.IO; 12 using System.IO;
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 x)
19 { 19 {
20 var st = new StackTrace(x, true); 20 var st = new StackTrace(x, true);
21 var frames = st.GetFrames(); 21 var frames = st.GetFrames();
22   22  
23 StringBuilder sb = new StringBuilder(); 23 StringBuilder sb = new StringBuilder();
24 sb.Append(Enumerable.Repeat('-', 75).ToArray()); 24 sb.Append(Enumerable.Repeat('-', 75).ToArray());
25   25  
26 int indent = 0; 26 int indent = 0;
27 foreach (var frame in frames) 27 foreach (var frame in frames)
28 { 28 {
29 if (frame.GetFileLineNumber() < 1) 29 if (frame.GetFileLineNumber() < 1)
30 continue; 30 continue;
31   31  
32 sb.Append(Enumerable.Repeat(' ', indent).ToArray()); 32 sb.Append(Enumerable.Repeat(' ', indent).ToArray());
33 sb.Append(@" -> "); 33 sb.Append(@" -> ");
34 sb.Append("File: "); 34 sb.Append("File: ");
35 sb.Append(string.Join( 35 sb.Append(string.Join(
36 Path.DirectorySeparatorChar.ToString(), 36 Path.DirectorySeparatorChar.ToString(),
37 frame.GetFileName() 37 frame.GetFileName()
38 .Split(Path.DirectorySeparatorChar) 38 .Split(Path.DirectorySeparatorChar)
39 .Reverse() 39 .Reverse()
40 .Take(2) 40 .Take(2)
41 .Reverse() 41 .Reverse()
42 ) 42 )
43 ); 43 );
44 sb.Append(@" Method: "); 44 sb.Append(@" Method: ");
45 sb.Append(frame.GetMethod().Name); 45 sb.Append(frame.GetMethod().Name);
46 sb.Append(@" Line and Column : "); 46 sb.Append(@" Line and Column : ");
47 sb.Append(frame.GetFileLineNumber()); 47 sb.Append(frame.GetFileLineNumber());
48 sb.Append(@":"); 48 sb.Append(@":");
49 sb.Append(frame.GetFileColumnNumber()); 49 sb.Append(frame.GetFileColumnNumber());
50 sb.Append(Environment.NewLine); 50 sb.Append(Environment.NewLine);
51   51  
52 indent += 4; 52 indent += 1;
53 } 53 }
54   54  
55 sb.Append(Enumerable.Repeat('-', 75).ToArray()); 55 sb.Append(Enumerable.Repeat('-', 75).ToArray());
56 sb.Append(x); 56 sb.Append(x);
57 sb.Append(Enumerable.Repeat('-', 75).ToArray()); 57 sb.Append(Enumerable.Repeat('-', 75).ToArray());
58   58  
59 return sb.ToString(); 59 return sb.ToString();
60 } 60 }
61 } 61 }
62 } 62 }
63   63