Sparkdo.AuditLogging.EntityFrameworkCore 1.0.1

There is a newer prerelease version of this package available.
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" />
                    
Directory.Packages.props
<PackageReference Include="Sparkdo.AuditLogging.EntityFrameworkCore" />
                    
Project file
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
                    
#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
                    
Install as a Cake Addin
#tool nuget:?package=Sparkdo.AuditLogging.EntityFrameworkCore&version=1.0.1
                    
Install as a Cake Tool

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 的审计日志实现,可以通过以下方式扩展:

  1. 继承 SparkdoAuditLoggingDbContext 来添加自定义实体
  2. 实现自定义的仓储类来扩展数据访问功能
  3. 通过 SparkdoAuditLoggingDbContextModelBuilderExtensions 来自定义实体映射
  4. 配置自定义的数据库表前缀和模式

代码结构说明

本项目包含以下主要组件:

数据库上下文

  • SparkdoAuditLoggingDbContext: 审计日志数据库上下文实现
  • IAuditLoggingDbContext: 审计日志数据库上下文接口

仓储实现

  • EFCoreAuditLogRepository: 审计日志仓储实现
  • EFCoreAuditLogExcelFileRepository: 审计日志Excel文件仓储实现

数据库模型配置

  • SparkdoAuditLoggingDbContextModelBuilderExtensions: 数据库模型构建器扩展

配置类

  • SparkdoAuditLoggingDbProperties: 数据库属性配置类

模块配置

  • SparkdoAuditLoggingEntityFrameworkCoreModule: 审计日志EntityFrameworkCore模块配置

所有公共接口和类都添加了详细的 XML 文档注释,便于开发者理解和使用。

Product 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.

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