可以在AbpAuditLogs表中添加列吗? 例如,我们想将ErrorCode添加到AbpAuditLogs表。如果可能,如何将ErroCode发送到相关方法?
答案 0 :(得分:1)
您可以继承AuditingStore
并将CustomData
设置为错误代码:
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);
}
}
您可以像这样抛出UserFriendlyException
:
throw new UserFriendlyException(526, "Error occurred 526");
然后替换模块中的IAuditingStore
:
// using Abp.Configuration.Startup;
public override void PreInitialize()
{
Configuration.ReplaceService<IAuditingStore, MyAuditingStore>();
}