是否可以将列添加到 AbpAuditLogs table?

Is it possible to add column to AbpAuditLogs table?

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

您可以继承 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>();
}