diff --git a/aspnet-core/framework/auditing/LINGYUN.Abp.AspNetCore.Auditing/FodyWeavers.xml b/aspnet-core/framework/auditing/LINGYUN.Abp.AspNetCore.Auditing/FodyWeavers.xml new file mode 100644 index 000000000..1715698cc --- /dev/null +++ b/aspnet-core/framework/auditing/LINGYUN.Abp.AspNetCore.Auditing/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/framework/auditing/LINGYUN.Abp.AspNetCore.Auditing/LINGYUN.Abp.AspNetCore.Auditing.csproj b/aspnet-core/framework/auditing/LINGYUN.Abp.AspNetCore.Auditing/LINGYUN.Abp.AspNetCore.Auditing.csproj new file mode 100644 index 000000000..4589f07e1 --- /dev/null +++ b/aspnet-core/framework/auditing/LINGYUN.Abp.AspNetCore.Auditing/LINGYUN.Abp.AspNetCore.Auditing.csproj @@ -0,0 +1,20 @@ + + + + + + + net9.0 + LINGYUN.Abp.AspNetCore.Auditing + LINGYUN.Abp.AspNetCore.Auditing + false + false + false + + + + + + + + diff --git a/aspnet-core/framework/auditing/LINGYUN.Abp.AspNetCore.Auditing/LINGYUN/Abp/AspNetCore/Auditing/AbpAspNetCoreAuditingHeaderOptions.cs b/aspnet-core/framework/auditing/LINGYUN.Abp.AspNetCore.Auditing/LINGYUN/Abp/AspNetCore/Auditing/AbpAspNetCoreAuditingHeaderOptions.cs new file mode 100644 index 000000000..647ea909a --- /dev/null +++ b/aspnet-core/framework/auditing/LINGYUN.Abp.AspNetCore.Auditing/LINGYUN/Abp/AspNetCore/Auditing/AbpAspNetCoreAuditingHeaderOptions.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; + +namespace LINGYUN.Abp.AspNetCore.Auditing; +public class AbpAspNetCoreAuditingHeaderOptions +{ + /// + /// 是否在审计日志中记录Http请求头,默认: true + /// + public bool IsEnabled { get; set; } + /// + /// 要记录的Http请求头 + /// + public IList HttpHeaders { get; } + public AbpAspNetCoreAuditingHeaderOptions() + { + IsEnabled = true; + HttpHeaders = new List(); + } +} diff --git a/aspnet-core/framework/auditing/LINGYUN.Abp.AspNetCore.Auditing/LINGYUN/Abp/AspNetCore/Auditing/AbpAspNetCoreAuditingModule.cs b/aspnet-core/framework/auditing/LINGYUN.Abp.AspNetCore.Auditing/LINGYUN/Abp/AspNetCore/Auditing/AbpAspNetCoreAuditingModule.cs new file mode 100644 index 000000000..119d69635 --- /dev/null +++ b/aspnet-core/framework/auditing/LINGYUN.Abp.AspNetCore.Auditing/LINGYUN/Abp/AspNetCore/Auditing/AbpAspNetCoreAuditingModule.cs @@ -0,0 +1,17 @@ +using Volo.Abp.AspNetCore; +using Volo.Abp.Auditing; +using Volo.Abp.Modularity; + +namespace LINGYUN.Abp.AspNetCore.Auditing; + +[DependsOn(typeof(AbpAspNetCoreModule))] +public class AbpAspNetCoreAuditingModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + options.Contributors.Add(new AspNetCoreRecordHeaderAuditLogContributor()); + }); + } +} diff --git a/aspnet-core/framework/auditing/LINGYUN.Abp.AspNetCore.Auditing/LINGYUN/Abp/AspNetCore/Auditing/AspNetCoreRecordHeaderAuditLogContributor.cs b/aspnet-core/framework/auditing/LINGYUN.Abp.AspNetCore.Auditing/LINGYUN/Abp/AspNetCore/Auditing/AspNetCoreRecordHeaderAuditLogContributor.cs new file mode 100644 index 000000000..67f4a59d3 --- /dev/null +++ b/aspnet-core/framework/auditing/LINGYUN.Abp.AspNetCore.Auditing/LINGYUN/Abp/AspNetCore/Auditing/AspNetCoreRecordHeaderAuditLogContributor.cs @@ -0,0 +1,51 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using System.Collections.Generic; +using System.Collections.Immutable; +using Volo.Abp.Auditing; +using Volo.Abp.Data; +using Volo.Abp.DependencyInjection; + +namespace LINGYUN.Abp.AspNetCore.Auditing; +public class AspNetCoreRecordHeaderAuditLogContributor : AuditLogContributor, ITransientDependency +{ + private const string HttpHeaderRecordKey = "HttpHeaders"; + + public AspNetCoreRecordHeaderAuditLogContributor() + { + } + + public override void PreContribute(AuditLogContributionContext context) + { + var options = context.ServiceProvider.GetRequiredService>(); + if (!options.Value.IsEnabled) + { + return; + } + + var httpContext = context.ServiceProvider.GetRequiredService().HttpContext; + if (httpContext == null) + { + return; + } + + if (context.AuditInfo.HasProperty(HttpHeaderRecordKey)) + { + return; + } + + var headerRcords = new Dictionary(); + var httpHeaders = httpContext.Request.Headers.ToImmutableDictionary(); + + foreach (var headerKey in options.Value.HttpHeaders) + { + if (httpHeaders.TryGetValue(headerKey, out var headers)) + { + headerRcords[headerKey] = headers.JoinAsString(";"); + } + } + + context.AuditInfo.SetProperty(HttpHeaderRecordKey, headerRcords); + } +} diff --git a/aspnet-core/framework/auditing/LINGYUN.Abp.AspNetCore.Auditing/README.md b/aspnet-core/framework/auditing/LINGYUN.Abp.AspNetCore.Auditing/README.md new file mode 100644 index 000000000..de6175010 --- /dev/null +++ b/aspnet-core/framework/auditing/LINGYUN.Abp.AspNetCore.Auditing/README.md @@ -0,0 +1,19 @@ +# LINGYUN.Abp.AspNetCore.Auditing + +审计日期扩展模块, 用于在审计日志中加入特定的Http请求头记录 + +## 模块引用 + + +```csharp +[DependsOn(typeof(AbpAspNetCoreAuditingModule))] +public class YouProjectModule : AbpModule +{ + // other +} +``` + +## 配置项 + +* AbpAspNetCoreAuditingHeaderOptions.IsEnabled 是否在审计日志中记录Http请求头,默认: true +* AbpAspNetCoreAuditingHeaderOptions.HttpHeaders 需要在审计日志中记录的Http请求头列表