I'm working on a greenfield Web API and need to log users' actions in a friendly way. I can see its easy to gather the logged in user, the controller, the action, and parameters like this post What I am looking for is away to give human readable friendly messages like:
- "Paul Logged in" + timestamp
- "Paul Created a new product (some product metadata)" + timestamp
- "Paul Deleted Product xyz" + timestamp
I could adapt the answer here and then use a lookup table on the controller and action to translate to my human readable string with some token replacements but I can see that being a maintenance overhead when new actions are added. It also means a developer might forget to put the call in and we miss auditing.
Is there a way I can use an annotation on the action to specify what my human readable log message will be? (possibly with tokens) Has anybody done this in a generic manner without the code becoming totally custom to that application?