55using Microsoft . AspNetCore . SignalR ;
66using Microsoft . Extensions . Logging ;
77using System ;
8+ using System . Linq ;
89using System . Threading . Tasks ;
910using WART_Core . Entity ;
11+ using WART_Core . Filters ;
1012using WART_Core . Hubs ;
1113
1214namespace WART_Core . Controllers
@@ -51,16 +53,21 @@ public override async void OnActionExecuted(ActionExecutedContext context)
5153 {
5254 if ( context ? . Result is ObjectResult objectResult )
5355 {
54- // get the request objects from RouteData
55- var request = context . RouteData . Values [ RouteDataKey ] ;
56- var httpMethod = context . HttpContext ? . Request . Method ;
57- var httpPath = context . HttpContext ? . Request . Path ;
58- var remoteAddress = context . HttpContext ? . Connection . RemoteIpAddress ? . ToString ( ) ;
59- // get the object response
60- var response = objectResult . Value ;
61- // create the new WartEvent and broadcast to all clients
62- var wartEvent = new WartEvent ( request , response , httpMethod , httpPath , remoteAddress ) ;
63- await SendToHub ( wartEvent ) ;
56+ // check for wart exclusion
57+ var exclusion = context . Filters . Any ( f => f . GetType ( ) . Name == nameof ( ExcludeWartAttribute ) ) ;
58+ if ( ! exclusion )
59+ {
60+ // get the request objects from RouteData
61+ var request = context . RouteData . Values [ RouteDataKey ] ;
62+ var httpMethod = context . HttpContext ? . Request . Method ;
63+ var httpPath = context . HttpContext ? . Request . Path ;
64+ var remoteAddress = context . HttpContext ? . Connection . RemoteIpAddress ? . ToString ( ) ;
65+ // get the object response
66+ var response = objectResult . Value ;
67+ // create the new WartEvent and broadcast to all clients
68+ var wartEvent = new WartEvent ( request , response , httpMethod , httpPath , remoteAddress ) ;
69+ await SendToHub ( wartEvent ) ;
70+ }
6471 }
6572
6673 base . OnActionExecuted ( context ) ;
@@ -77,7 +84,7 @@ private async Task SendToHub(WartEvent wartEvent)
7784 {
7885 await _hubContext ? . Clients . All . SendAsync ( "Send" , wartEvent . ToString ( ) ) ;
7986
80- _logger ? . LogInformation ( message : " WartEvent" , wartEvent . ToString ( ) ) ;
87+ _logger ? . LogInformation ( message : nameof ( WartEvent ) , wartEvent . ToString ( ) ) ;
8188 }
8289 catch ( Exception ex )
8390 {
0 commit comments