Reputation: 875
I have following ActionFilter
attributes implemented for web apis:
LogRequest
: This logs the request and response in OnActionExecuted
method.
ValidateModel
: This validates the model and returns BadRequest
by setting Response
in OnActionExecuting` method.
Now the problem is that - requests for which we have returned BadRequest
(from ValidateModel
attribute) are not being logged because OnActionExecuted
(of LogRequest
attribute) is not getting fired.
Is there any way I can fire OnActionExecuted
intentionally?
Upvotes: 0
Views: 351
Reputation: 487
Don't think so.
Some options:
- depending on your requirements you could implement a message handler for logging purposes.
- don't execute action logic if you model state is not valid and return BadRequest in OnActionExecuted after logging.
- implement a logging function and just call it whereever you need it.
...
Upvotes: 0