It is possible to add column to AbpAuditLogs table? for example we want to add ErrorCode to AbpAuditLogs table. If possible, how can send ErroCode to related method?
You can subclass AuditingStore
and set CustomData
to the error code:
public class MyAuditingStore : AuditingStore
{
public MyAuditingStore(IRepository<AuditLog, long> auditLogRepository)
: base(auditLogRepository)
{
}
public override Task SaveAsync(AuditInfo auditInfo)
{
auditInfo.CustomData = (auditInfo.Exception as IHasErrorCode)?.Code.ToString();
return base.SaveAsync(auditInfo);
}
}
You can throw UserFriendlyException
like this:
throw new UserFriendlyException(526, "Error occurred 526");
Then replace IAuditingStore
in your module:
// using Abp.Configuration.Startup;
public override void PreInitialize()
{
Configuration.ReplaceService<IAuditingStore, MyAuditingStore>();
}