11namespace RollbarDotNet . Builder
22{
3+ using System ;
34 using System . Collections . Generic ;
45 using System . Diagnostics ;
6+ using System . Linq ;
57 using Payloads ;
6- using Trace = Payloads . Trace ;
8+ using Exception = System . Exception ;
79
810 public class ExceptionBuilder : IExceptionBuilder
911 {
10- public void Execute ( Payload payload , System . Exception exception )
12+ public void Execute ( Payload payload , Exception exception )
1113 {
12- if ( payload == null )
14+ if ( payload == null )
1315 {
14- throw new System . ArgumentNullException ( nameof ( payload ) ) ;
16+ throw new ArgumentNullException ( nameof ( payload ) ) ;
1517 }
1618
17- if ( exception == null )
19+ if ( exception == null )
1820 {
19- throw new System . ArgumentNullException ( nameof ( exception ) ) ;
21+ throw new ArgumentNullException ( nameof ( exception ) ) ;
2022 }
2123
22- var traceChain = new List < Trace > ( ) ;
24+ var traceChain = new List < Payloads . Trace > ( ) ;
2325 this . BuildTraceList ( exception , traceChain ) ;
24- if ( traceChain . Count > 0 )
26+ if ( traceChain . Count > 0 )
2527 {
2628 payload . Data . Body . TraceChain = traceChain ;
2729 }
2830 }
2931
30- protected void BuildTraceList ( System . Exception exception , List < Trace > traceList )
32+ protected void BuildTraceList ( Exception exception , List < Payloads . Trace > traceList )
3133 {
32- var trace = new Trace ( ) ;
34+ var trace = new Payloads . Trace ( ) ;
3335 trace . Exception = this . BuildException ( exception ) ;
3436 trace . Frames = this . BuildFrames ( exception ) ;
3537 traceList . Add ( trace ) ;
@@ -39,18 +41,26 @@ protected void BuildTraceList(System.Exception exception, List<Trace> traceList)
3941 }
4042 }
4143
42- protected List < Frame > BuildFrames ( System . Exception exception )
44+ protected List < Frame > BuildFrames ( Exception exception )
4345 {
4446 var frames = new List < Frame > ( ) ;
4547 var stacktrace = new StackTrace ( exception , true ) ;
4648 foreach ( var stackTraceFrame in stacktrace . GetFrames ( ) )
4749 {
50+ var method = stackTraceFrame . GetMethod ( ) ;
51+ var methodParameters = method . GetParameters ( ) ;
52+ var parameters = methodParameters . Length == 0
53+ ? string . Empty
54+ : method . GetParameters ( )
55+ . Select ( p => $ "{ p . ParameterType . FullName } { p . Name } ")
56+ . Aggregate ( ( p1 , p2 ) => $ "{ p1 } , { p2 } ") ;
57+ var methodName = $ "{ method . DeclaringType . FullName } .{ method . Name } ({ parameters } )";
4858 var frame = new Frame
4959 {
5060 Filename = stackTraceFrame . GetFileName ( ) ,
5161 ColumnNumber = stackTraceFrame . GetFileColumnNumber ( ) ,
5262 LineNumber = stackTraceFrame . GetFileLineNumber ( ) ,
53- Method = stackTraceFrame . GetMethod ( ) ? . ToString ( )
63+ Method = methodName
5464 } ;
5565 frames . Add ( frame ) ;
5666 }
@@ -63,12 +73,12 @@ protected List<Frame> BuildFrames(System.Exception exception)
6373 return frames ;
6474 }
6575
66- protected Exception BuildException ( System . Exception exception )
76+ protected Payloads . Exception BuildException ( Exception exception )
6777 {
68- var payloadException = new Exception ( ) ;
78+ var payloadException = new Payloads . Exception ( ) ;
6979 payloadException . Class = exception . GetType ( ) . Name ;
7080 payloadException . Message = exception . Message ;
7181 return payloadException ;
7282 }
7383 }
74- }
84+ }
0 commit comments