[Question / Feature] Auditing Default User(s)
Hi,
When we insert data into the system via code (may be a background job or task that was run), rather than a user updating an entity, the CreatorId etc. is NULL (as expected since it's not a user task). Would it be possible to do something like this:
Configure<AuditingOptions>(options => {
options.DefaultUserId = <GuidHere>;
});
This would allow us to set a 'system user' ID that we could then query the DB for and see what rows have been affected by system tasks rather than just query for NULL. While NULL would work, if we had several separated services that are doing tasks, we could have a unique system ID for each service - this would allow us to define their IDs and we could query the system for "rows affected by Service A" etc.
Hope that makes sense!
You can pass the userid to the background task by passing the parameters and then use it in the task.
@wayneboyles I believe options.DefaultUserId is not a good solution.
But there is an ApplicationName option for the audit logs:
Configure<AuditingOptions>(options => {
options.ApplicationName = "your service name";
});
In this way, every service can write logs isolated between each other.
Also, Audit logging in ABP is extensible. Example:
Configure<AuditingOptions>(options => {
options.Contributors.Add(new MyAuditLogContributor());
});
MyAuditLogContributor is a class (should be written by you) inheriting from the AuditLogContributor. In this way, you can customize audit logs (even you can set UserId if you really want). AuditLogInfo also implements IHasExtraProperties so you can add custom properties too.
So, there are many ways :)