【问题标题】:Configure audit logging for Application Services in ASP.NET Boilerplate在 ASP.NET 样板中为应用程序服务配置审核日志记录
【发布时间】:2019-03-28 03:40:19
【问题描述】:

我正在尝试确定是否有办法删除 ASP.NET 样板代码中默认提供的审核日志。

查看文档,似乎使用以下方法从审核配置中删除选择器应该有效,但它没有。

Configuration.Auditing.Selectors.Clear()

原因是,比如说,如果我想启用审计,但只想审计某些服务而不是 IApplicationService 类型的所有服务。

我曾尝试将上述行放在各个模块中,但均未成功。所有服务调用都记录在AbpAuditLogs 表中。

【问题讨论】:

  • 你用什么方法调用Clear
  • ClearPreInitialize 文件中的PreInitialize 方法中被调用。

标签: c# asp.net-core configuration aspnetboilerplate audit-logging


【解决方案1】:

背景

ASP.NET Boilerplate 提供了创建应用程序服务的基础结构。

CreateControllersForAppServices 方法获取一个程序集并将所有应用程序服务转换为该程序集中的 MVC 控制器。

ABP 为 ASP.NET Core 定义了一些预建过滤器。所有这些都默认添加到所有控制器的所有操作中。

——https://aspnetboilerplate.com/Pages/Documents/AspNet-Core

问题

Configuration.Auditing.Selectors.Clear()AuditingInterceptor 处理它,而不是操作过滤器。

AbpAuditActionFilterdefaultValue 作为true 传递给_auditingHelper.ShouldSaveAudit(...)

defaultValue 最终由AuditingHelper 返回。

解决方法

我们不能轻易替换AbpAuditActionFilter,但我们可以替换AuditingHelper

  1. 复制AuditingHelper并将其重命名为IgnoreDefaultAuditingHelper

  2. 修改AuditingHelper.ShouldSaveAudit的最后一行忽略defaultValue

    public bool ShouldSaveAudit(MethodInfo methodInfo, bool defaultValue = false)
    {
        // ...
    
        return false;
        // return defaultValue;
    }
    
  3. 替换模块的PreInitialize 方法中的IAuditingHelper

    public override void PreInitialize()
    {
        Configuration.ReplaceService<IAuditingHelper, IgnoreDefaultAuditingHelper>();
    }
    

【讨论】:

    猜你喜欢
    • 2013-05-25
    • 2020-04-22
    • 1970-01-01
    • 2013-02-28
    • 2016-03-23
    • 2011-03-18
    • 2013-01-12
    • 2019-12-01
    • 1970-01-01
    相关资源
    最近更新 更多