gpt4 book ai didi

c# - 在 ASP.NET 样板中为应用程序服务配置审计日志记录

转载 作者:行者123 更新时间:2023-11-30 22:58:32 24 4
gpt4 key购买 nike

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

查看文档,似乎使用以下应该 从审核配置中删除选择器,但事实并非如此。

Configuration.Auditing.Selectors.Clear()

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

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

最佳答案

背景

ASP.NET Boilerplate provides the infrastructure to create application services.

The CreateControllersForAppServices method gets an assembly and converts all the application services to MVC controllers in that assembly.

ABP defines some pre-built filters for ASP.NET Core. All of them are added to all actions of all controllers by default.

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

问题

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

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

关于c# - 在 ASP.NET 样板中为应用程序服务配置审计日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52956865/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com