I am new to the use of audit.net. I need to audit a series of custom values from the parameters received in the action method as follows.
[AuditField("User","reqLogin.User")]
[AuditCustom(EventTypeName = "AccesoAction")]
public async Task<IActionResult> Acceso(LoginRequest reqLogin)
{
...
}
I have to create a CustomField with FieldName "User" and value, the value of the User attribute of parameter reqLogin (reqLogin.User).
I'm extending the AuditAttribute class, to overwrite the OnActionExecutionAsync method and add the CustomField.
public class AuditCustomAttribute : AuditAttribute
{
public override Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
lock (context.ActionDescriptor.Parameters)
{
foreach (AuditFieldAttribute apa in context.ActionDescriptor.Parameters.Cast<ControllerParameterDescriptor>().First().ParameterInfo.Member.GetCustomAttributes<AuditFieldAttribute>())
{
// create CustomField and add to context
}
}
return base.OnActionExecutionAsync(context, next);
}
}
Finally, in my custom AuditDataProvider class, I would audit the customFields that arrived in the auditevent field of method:
public override object InsertEvent(AuditEvent auditEvent)
How would it be possible? Thanks