@@ -13,8 +13,8 @@ public static class DetailedExceptionInfoBuilder
13
13
/// Builds the detailed exception info.
14
14
/// </summary>
15
15
/// <param name="e">The exception.</param>
16
- /// <returns></returns >
17
- public static string ? Build ( Exception e )
16
+ /// <param name="htmlFormatting">if set to <c>true</c> then HTML formatting will be added to text.</param >
17
+ public static string ? Build ( Exception e , bool htmlFormatting )
18
18
{
19
19
var trace = new StackTrace ( e , true ) ;
20
20
@@ -28,12 +28,18 @@ public static class DetailedExceptionInfoBuilder
28
28
? ""
29
29
: $ "[{ fileLineNumber } :{ fileColumnNumber } ]";
30
30
31
- return
32
- $ "<b>{ positionPrefix } { e . GetType ( ) } : { e . Message } </b>{ Environment . NewLine } { trace } { BuildInnerExceptionData ( 1 , e . InnerException ) } "
33
- . Replace ( Environment . NewLine , "<br />" ) ;
31
+ var result = ( htmlFormatting ? "<b>" : "" )
32
+ + $ "{ positionPrefix } { e . GetType ( ) } : { e . Message } "
33
+ + ( htmlFormatting ? "</b>" : "" )
34
+ + $ "{ Environment . NewLine } { trace } { BuildInnerExceptionData ( 1 , e . InnerException , htmlFormatting ) } ";
35
+
36
+ if ( htmlFormatting )
37
+ result = result . Replace ( Environment . NewLine , "<br />" ) ;
38
+
39
+ return result ;
34
40
}
35
41
36
- private static string ? BuildInnerExceptionData ( int currentLevel , Exception ? e )
42
+ private static string ? BuildInnerExceptionData ( int currentLevel , Exception ? e , bool htmlFormatting )
37
43
{
38
44
if ( e == null )
39
45
return null ;
@@ -54,8 +60,10 @@ public static class DetailedExceptionInfoBuilder
54
60
? " " + currentLevel . ToString ( CultureInfo . InvariantCulture )
55
61
: "" ;
56
62
57
- return
58
- $ "<br /><b>[Inner Exception{ levelText } ]{ positionPrefix } { e . GetType ( ) } : { e . Message } </b>{ Environment . NewLine } { trace } { BuildInnerExceptionData ( currentLevel + 1 , e . InnerException ) } ";
63
+ return ( htmlFormatting ? "<br /><b>" : "" )
64
+ + $ "[Inner Exception{ levelText } ]{ positionPrefix } { e . GetType ( ) } : { e . Message } "
65
+ + ( htmlFormatting ? "</b>" : "" )
66
+ + $ "{ Environment . NewLine } { trace } { BuildInnerExceptionData ( currentLevel + 1 , e . InnerException , htmlFormatting ) } ";
59
67
}
60
68
}
61
69
}
0 commit comments