I'm using aspnet boilerplate and I've successfully trimmed down exactly which methods are/are not logged, by using the [DisableAuditing]
and [Audited]
attributes. So that part is working great, and I'm satisfied with my logging levels. However, I don't understand how to effectively use the CustomData field. I'd like to use this field to save certain additional data that is not captured by default, but I don't understand how to set it, or where. Thanks in advance for any advice.
Asked
Active
Viewed 873 times
0

Vivek Nuna
- 25,472
- 25
- 109
- 197

Bobby
- 119
- 11
-
hi, have you managed to pass the message to custome data ? – Shahid Od Feb 12 '21 at 08:43
1 Answers
2
You can subclass AuditingStore
and set CustomData
to your data:
public class MyAuditingStore : AuditingStore
{
public MyAuditingStore(IRepository<AuditLog, long> auditLogRepository)
: base(auditLogRepository)
{
}
public override Task SaveAsync(AuditInfo auditInfo)
{
auditInfo.CustomData = "certain additional data that is not captured by default";
return base.SaveAsync(auditInfo);
}
}
Then replace IAuditingStore
in your module:
// using Abp.Configuration.Startup;
public override void PreInitialize()
{
Configuration.ReplaceService<IAuditingStore, MyAuditingStore>(DependencyLifeStyle.Transient);
}

aaron
- 39,695
- 6
- 46
- 102
-
This is a great solution and it answers my original question. However, as a followup question, is there any way to pass a custom "message" to the CustomData field? With the proposed solution, I can only create a message using fields the AuditInfo already has. – Bobby Mar 30 '18 at 16:06
-
I just want to know if there is any way to pass a string to the SaveAsync method that I can put in the CustomData field, besides what is already available in the AuditInfo object. Can I extend AuditInfo to have more attributes? – Bobby Mar 30 '18 at 16:34
-
1No, unless you rewrite the Auditing logic. But you can inject services into `AuditingStore` to retrieve other information. – aaron Mar 30 '18 at 16:40