@@ -9,6 +9,7 @@ public sealed class ExceptionlessDiagnosticListener : IObserver<KeyValuePair<str
99 private const string HandledExceptionEvent = "Microsoft.AspNetCore.Diagnostics.HandledException" ;
1010 private const string DiagnosticsUnhandledExceptionEvent = "Microsoft.AspNetCore.Diagnostics.UnhandledException" ;
1111 private const string HostingUnhandledExceptionEvent = "Microsoft.AspNetCore.Hosting.UnhandledException" ;
12+ private const string HostingDiagnosticsUnhandledExceptionEvent = "Microsoft.AspNetCore.Hosting.Diagnostics.UnhandledException" ;
1213 private const string MiddlewareExceptionEvent = "Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareException" ;
1314 private readonly ExceptionlessClient _client ;
1415
@@ -20,24 +21,36 @@ public void OnCompleted() { }
2021
2122 public void OnError ( Exception error ) { }
2223
24+ internal static bool IsRelevantEvent ( string eventName ) {
25+ return String . Equals ( eventName , HandledExceptionEvent , StringComparison . Ordinal ) ||
26+ String . Equals ( eventName , DiagnosticsUnhandledExceptionEvent , StringComparison . Ordinal ) ||
27+ String . Equals ( eventName , HostingUnhandledExceptionEvent , StringComparison . Ordinal ) ||
28+ String . Equals ( eventName , HostingDiagnosticsUnhandledExceptionEvent , StringComparison . Ordinal ) ||
29+ String . Equals ( eventName , MiddlewareExceptionEvent , StringComparison . Ordinal ) ;
30+ }
31+
2332 public void OnNext ( KeyValuePair < string , object > diagnosticEvent ) {
2433 switch ( diagnosticEvent . Key ) {
2534 case HandledExceptionEvent :
2635 SubmitException ( diagnosticEvent . Value , diagnosticEvent . Key , false ) ;
2736 break ;
2837 case DiagnosticsUnhandledExceptionEvent :
2938 case HostingUnhandledExceptionEvent :
39+ case HostingDiagnosticsUnhandledExceptionEvent :
3040 SubmitException ( diagnosticEvent . Value , diagnosticEvent . Key , true ) ;
3141 break ;
3242 case MiddlewareExceptionEvent :
43+ if ( diagnosticEvent . Value is null )
44+ break ;
45+
3346 string middlewareName = GetPropertyValue ( diagnosticEvent . Value , "name" ) as string ;
3447 SubmitException ( diagnosticEvent . Value , middlewareName ?? diagnosticEvent . Key , true ) ;
3548 break ;
3649 }
3750 }
3851
3952 private void SubmitException ( object payload , string submissionMethod , bool isUnhandledError ) {
40- if ( payload == null )
53+ if ( payload is null )
4154 return ;
4255
4356 var httpContext = GetPropertyValue ( payload , "httpContext" ) as HttpContext ;
@@ -54,6 +67,9 @@ private void SubmitException(object payload, string submissionMethod, bool isUnh
5467 }
5568
5669 private static object GetPropertyValue ( object payload , string propertyName ) {
70+ if ( payload is null )
71+ return null ;
72+
5773 return payload . GetType ( )
5874 . GetProperty ( propertyName , BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . IgnoreCase ) ?
5975 . GetValue ( payload ) ;
0 commit comments