1- using System . Diagnostics ;
1+ using System . Diagnostics ;
22using System . Text ;
33using DebugProbe . AspNetCore . Models ;
44using DebugProbe . AspNetCore . Options ;
@@ -58,14 +58,18 @@ public async Task Invoke(HttpContext context, DebugEntryStore store)
5858 var started = Stopwatch . StartNew ( ) ;
5959
6060 var exception = false ;
61+ string ? exceptionMessage = null ;
62+ string ? exceptionStackTrace = null ;
6163
6264 try
6365 {
6466 await _next ( context ) ;
6567 }
66- catch
68+ catch ( Exception ex )
6769 {
6870 exception = true ;
71+ exceptionMessage = ex . Message ;
72+ exceptionStackTrace = ex . StackTrace ;
6973 throw ;
7074 }
7175 finally
@@ -100,25 +104,25 @@ public async Task Invoke(HttpContext context, DebugEntryStore store)
100104 $ "{ context . Request . Path } { context . Request . QueryString } ",
101105 RequestBody = Trim ( requestBody ) ,
102106
103-
104107 // Response
105108 ResponseBody = Trim ( responseBody ) ,
106109
110+ // Exception
111+ ExceptionMessage = exceptionMessage ,
112+ ExceptionStackTrace = Trim ( exceptionStackTrace , max : 4000 ) ,
107113
108114 // Headers
109115 Headers = context . Request . Headers . ToDictionary ( x => x . Key , x => x . Value . ToString ( ) ) ,
110116
111-
112117 // Other
113118 Timestamp = DateTime . UtcNow ,
114-
115119 } ) ;
116120 }
117121 }
118122
119- private string Trim ( string value , int max = 2000 )
123+ private string Trim ( string ? value , int max = 2000 )
120124 {
121- if ( string . IsNullOrEmpty ( value ) ) return value ;
125+ if ( string . IsNullOrEmpty ( value ) ) return value ?? string . Empty ;
122126 return value . Length <= max ? value : value . Substring ( 0 , max ) ;
123127 }
124- }
128+ }
0 commit comments