在 ASP.NET 样板中为应用程序服务配置审核日志记录
Configure audit logging for Application Services in ASP.NET Boilerplate
我正在尝试确定是否有办法删除 ASP.NET 样板代码中默认提供的审核日志记录。
查看文档,似乎使用以下 从审计配置中删除选择器应该 有效,但它不起作用。
Configuration.Auditing.Selectors.Clear()
原因是,比如说,如果我想启用审计,但只想审计某些服务而不是 IApplicationService
类型的所有服务。
我试过将上面这行代码放到各个模块中,但都没有成功。所有服务呼叫都记录在 AbpAuditLogs
table.
中
背景
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
处理它,而不是操作过滤器。
AbpAuditActionFilter
将 defaultValue
作为 true
传递给 _auditingHelper.ShouldSaveAudit(...)
。
defaultValue
最终由 AuditingHelper
返回。
解决方法
我们不能轻易替换AbpAuditActionFilter
,但我们可以替换AuditingHelper
:
复制AuditingHelper
并重命名为IgnoreDefaultAuditingHelper
。
修改AuditingHelper.ShouldSaveAudit
最后一行忽略defaultValue
:
public bool ShouldSaveAudit(MethodInfo methodInfo, bool defaultValue = false)
{
// ...
return false;
// return defaultValue;
}
在你的模块的PreInitialize
方法中替换IAuditingHelper
:
public override void PreInitialize()
{
Configuration.ReplaceService<IAuditingHelper, IgnoreDefaultAuditingHelper>();
}
我正在尝试确定是否有办法删除 ASP.NET 样板代码中默认提供的审核日志记录。
查看文档,似乎使用以下 从审计配置中删除选择器应该 有效,但它不起作用。
Configuration.Auditing.Selectors.Clear()
原因是,比如说,如果我想启用审计,但只想审计某些服务而不是 IApplicationService
类型的所有服务。
我试过将上面这行代码放到各个模块中,但都没有成功。所有服务呼叫都记录在 AbpAuditLogs
table.
背景
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
处理它,而不是操作过滤器。
AbpAuditActionFilter
将 defaultValue
作为 true
传递给 _auditingHelper.ShouldSaveAudit(...)
。
defaultValue
最终由 AuditingHelper
返回。
解决方法
我们不能轻易替换AbpAuditActionFilter
,但我们可以替换AuditingHelper
:
复制
AuditingHelper
并重命名为IgnoreDefaultAuditingHelper
。修改
AuditingHelper.ShouldSaveAudit
最后一行忽略defaultValue
:public bool ShouldSaveAudit(MethodInfo methodInfo, bool defaultValue = false) { // ... return false; // return defaultValue; }
在你的模块的
PreInitialize
方法中替换IAuditingHelper
:public override void PreInitialize() { Configuration.ReplaceService<IAuditingHelper, IgnoreDefaultAuditingHelper>(); }