I am trying to look for a more clean way to add audit trail function to an exist asp.net MVC and Web Api project which contains hundreds of Controller
and ApiController
.
The Audit trail log would look like below. Basically I just want to log In what time who did what
in this function.
UserID
ActionTime
Controller
Action
Anything I missed ? If there is . Please correct me. Thanks.
Currently I found there are some ways to make it .
Implement an
ActionFilterAttribute
and write my own log function in theOnActionExecuting
, and then decorate all the actions with this attribute.Implement a base
Controller
likeBaseController
for all the exist controller. And write log in theOnActionExecuting
. Then change all the controller to inherit fromBaseController
. (If it is wrong . Please correct me . Thanks.)For the
ApiController
. Implement aDelegatingHandler
to make it.
For 1 and 2. I need change to all the exist code to make it. like change base class or decorate with new attribute. Considering in my case, This will be a hard work. Because thousands of class or methods need to be changed . I thinks it is kind of verbose. So I wondered if there is some clean way like 3 for ApiController to make it. Thanks.