Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ConfigureAwait ContinueOnCapturedContext="false" />
</Weavers>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\..\..\..\configureawait.props" />
<Import Project="..\..\..\..\common.props" />

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<AssemblyName>LINGYUN.Abp.AspNetCore.Auditing</AssemblyName>
<PackageId>LINGYUN.Abp.AspNetCore.Auditing</PackageId>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<RootNamespace />
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Volo.Abp.AspNetCore" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.Generic;

namespace LINGYUN.Abp.AspNetCore.Auditing;
public class AbpAspNetCoreAuditingHeaderOptions
{
/// <summary>
/// 是否在审计日志中记录Http请求头,默认: true
/// </summary>
public bool IsEnabled { get; set; }
/// <summary>
/// 要记录的Http请求头
/// </summary>
public IList<string> HttpHeaders { get; }
public AbpAspNetCoreAuditingHeaderOptions()
{
IsEnabled = true;
HttpHeaders = new List<string>();
}
}
Original file line number Diff line number Diff line change
@@ -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<AbpAuditingOptions>(options =>
{
options.Contributors.Add(new AspNetCoreRecordHeaderAuditLogContributor());
});
}
}
Original file line number Diff line number Diff line change
@@ -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<IOptions<AbpAspNetCoreAuditingHeaderOptions>>();
if (!options.Value.IsEnabled)
{
return;
}

var httpContext = context.ServiceProvider.GetRequiredService<IHttpContextAccessor>().HttpContext;
if (httpContext == null)
{
return;
}

if (context.AuditInfo.HasProperty(HttpHeaderRecordKey))
{
return;
}

var headerRcords = new Dictionary<string, string>();
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);
}
}
Original file line number Diff line number Diff line change
@@ -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请求头列表
Loading