是否可以向AbpAuditLogs表添加列?

时间:2018-01-09 12:08:55

标签: aspnetboilerplate

可以在AbpAuditLogs表中添加列吗? 例如,我们想将ErrorCode添加到AbpAuditLogs表。如果可能,如何将ErroCode发送到相关方法?

1 个答案:

答案 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>();
}