Sparkdo.AuditLogging.EntityFrameworkCore
1.0.1
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Sparkdo.AuditLogging.EntityFrameworkCore --version 1.0.1
NuGet\Install-Package Sparkdo.AuditLogging.EntityFrameworkCore -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sparkdo.AuditLogging.EntityFrameworkCore" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sparkdo.AuditLogging.EntityFrameworkCore" Version="1.0.1" />
<PackageReference Include="Sparkdo.AuditLogging.EntityFrameworkCore" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Sparkdo.AuditLogging.EntityFrameworkCore --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Sparkdo.AuditLogging.EntityFrameworkCore, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Sparkdo.AuditLogging.EntityFrameworkCore@1.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Sparkdo.AuditLogging.EntityFrameworkCore&version=1.0.1
#tool nuget:?package=Sparkdo.AuditLogging.EntityFrameworkCore&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Sparkdo.AuditLogging.EntityFrameworkCore
Sparkdo 审计日志EntityFrameworkCore实现,提供基于EF Core的审计日志数据访问实现。
功能特性
- 基于 Entity Framework Core 的审计日志数据访问实现
- 完整的审计日志实体映射配置
- 支持审计日志查询和分析
- 支持多数据库提供程序
- 与 Sparkdo 框架无缝集成
安装
<PackageReference Include="Sparkdo.AuditLogging.EntityFrameworkCore" Version="x.x.x" />
核心组件
SparkdoAuditLoggingDbContext
审计日志数据库上下文,用于审计日志模块的Entity Framework Core数据库操作:
AuditLogs: 审计日志实体集合AuditLogExcelFiles: 审计日志Excel文件实体集合
EFCoreAuditLogRepository
基于EntityFrameworkCore的审计日志仓储实现:
GetListAsync(): 获取审计日志列表GetCountAsync(): 获取审计日志数量GetEntityChange(): 获取实体变更信息GetEntityChangeListAsync(): 获取实体变更列表GetEntityChangesWithUsernameAsync(): 获取带用户名的实体变更历史
EFCoreAuditLogExcelFileRepository
基于EntityFrameworkCore的审计日志Excel文件仓储实现:
GetListCreationTimeBeforeAsync(): 获取创建时间早于指定时间的审计日志Excel文件列表
数据库模型配置
SparkdoAuditLoggingDbContextModelBuilderExtensions: 数据库模型构建器扩展- 支持自定义表前缀和数据库模式
- 完整的索引配置以提高查询性能
使用示例
查询审计日志
public class AuditLogService
{
private readonly IAuditLogRepository _auditLogRepository;
public AuditLogService(IAuditLogRepository auditLogRepository)
{
_auditLogRepository = auditLogRepository;
}
public async Task<List<AuditLog>> GetRecentAuditLogsAsync()
{
return await _auditLogRepository.GetListAsync(
sorting: "ExecutionTime DESC",
maxResultCount: 50,
startTime: DateTime.Now.AddDays(-7)
);
}
public async Task<Dictionary<DateTime, double>> GetAverageExecutionDurationAsync()
{
return await _auditLogRepository.GetAverageExecutionDurationPerDayAsync(
startDate: DateTime.Now.AddDays(-30),
endDate: DateTime.Now
);
}
}
自定义数据库配置
// 在启动配置中自定义审计日志数据库配置
services.Configure<SparkdoAuditLoggingDbProperties>(options =>
{
options.DbTablePrefix = "MyApp_";
options.DbSchema = "audit";
});
扩展性
该库提供了基于 Entity Framework Core 的审计日志实现,可以通过以下方式扩展:
- 继承
SparkdoAuditLoggingDbContext来添加自定义实体 - 实现自定义的仓储类来扩展数据访问功能
- 通过
SparkdoAuditLoggingDbContextModelBuilderExtensions来自定义实体映射 - 配置自定义的数据库表前缀和模式
代码结构说明
本项目包含以下主要组件:
数据库上下文
SparkdoAuditLoggingDbContext: 审计日志数据库上下文实现IAuditLoggingDbContext: 审计日志数据库上下文接口
仓储实现
EFCoreAuditLogRepository: 审计日志仓储实现EFCoreAuditLogExcelFileRepository: 审计日志Excel文件仓储实现
数据库模型配置
SparkdoAuditLoggingDbContextModelBuilderExtensions: 数据库模型构建器扩展
配置类
SparkdoAuditLoggingDbProperties: 数据库属性配置类
模块配置
SparkdoAuditLoggingEntityFrameworkCoreModule: 审计日志EntityFrameworkCore模块配置
所有公共接口和类都添加了详细的 XML 文档注释,便于开发者理解和使用。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- JetBrains.Annotations (>= 2025.2.2)
- Microsoft.EntityFrameworkCore (>= 10.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.0)
- Microsoft.Extensions.Caching.Memory (>= 10.0.0)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.Configuration.CommandLine (>= 10.0.0)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.0)
- Microsoft.Extensions.Configuration.FileExtensions (>= 10.0.0)
- Microsoft.Extensions.Configuration.Json (>= 10.0.0)
- Microsoft.Extensions.Configuration.UserSecrets (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.DependencyModel (>= 10.0.0)
- Microsoft.Extensions.FileProviders.Composite (>= 10.0.0)
- Microsoft.Extensions.FileProviders.Embedded (>= 10.0.0)
- Microsoft.Extensions.FileProviders.Physical (>= 10.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Localization (>= 10.0.0)
- Microsoft.Extensions.Logging (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.0)
- Nito.AsyncEx.Context (>= 5.1.2)
- Sparkdo.AuditLogging.Domain (>= 1.0.1)
- Sparkdo.EntityFrameworkCore (>= 1.0.1)
- System.Linq.Dynamic.Core (>= 1.7.0)
- TimeZoneConverter (>= 7.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.2-preview.1 | 135 | 12/4/2025 |
| 1.0.1 | 166 | 11/27/2025 |
| 1.0.0 | 175 | 11/25/2025 |