Sparkdo 审计日志领域层,提供审计日志的核心业务逻辑和数据访问接口
License
—
Deps
60
Install Size
—
Vulns
✓ 0
Published
Feb 8, 2026
$ dotnet add package Sparkdo.AuditLogging.DomainSparkdo 审计日志领域层,提供审计日志的核心业务逻辑和数据访问接口。
<PackageReference Include="Sparkdo.AuditLogging.Domain" Version="x.x.x" />
审计日志实体类,记录系统操作的详细信息:
ApplicationName: 应用程序名称UserId: 用户IDUserName: 用户名TenantId: 租户IDTenantName: 租户名称ExecutionTime: 执行时间ExecutionDuration: 执行持续时间ClientIpAddress: 客户端IP地址Url: 请求URLHttpMethod: HTTP方法HttpStatusCode: HTTP状态码Exceptions: 异常信息EntityChanges: 实体变更集合Actions: 审计操作集合实体变更记录类,记录实体的变更历史:
ChangeTime: 变更时间ChangeType: 变更类型(创建/更新/删除)EntityId: 实体IDEntityTypeFullName: 实体类型全名PropertyChanges: 属性变更集合审计日志操作类,记录方法调用的操作信息:
ServiceName: 服务名称MethodName: 方法名称Parameters: 参数信息ExecutionTime: 执行时间ExecutionDuration: 执行持续时间审计日志仓储接口,提供审计日志数据访问功能:
GetListAsync(): 获取审计日志列表GetCountAsync(): 获取审计日志数量GetEntityChange(): 获取实体变更信息GetEntityChangeListAsync(): 获取实体变更列表GetEntityChangesWithUsernameAsync(): 获取带用户名的实体变更历史审计存储实现类,负责将审计日志信息保存到存储中:
SaveAsync(): 保存审计日志信息在模块中添加审计日志功能:
public class MyModule : Module
{
public override void ConfigureServices(IConfigureContext context)
{
// 审计日志会自动集成到框架中
// 只需确保 SparkdoAuditLoggingDomainModule 已加载
}
}
public class AuditLogAppService : ApplicationService
{
private readonly IAuditLogRepository _auditLogRepository;
public AuditLogAppService(IAuditLogRepository auditLogRepository)
{
_auditLogRepository = auditLogRepository;
}
public async Task<List<AuditLog>> GetAuditLogsAsync(DateTime? startTime = null, DateTime? endTime = null)
{
return await _auditLogRepository.GetListAsync(
startTime: startTime,
endTime: endTime,
maxResultCount: 100
);
}
public async Task<List<EntityChange>> GetEntityChangesAsync(string entityId, string entityTypeFullName)
{
return await _auditLogRepository.GetEntityChangeListAsync(
entityId: entityId,
entityTypeFullName: entityTypeFullName
);
}
}
该库提供了完整的审计日志领域实现,可以通过以下方式扩展:
IAuditLogRepository 来替换默认的数据访问实现AuditLog 或 EntityChange 来添加自定义属性IAuditingStore 来处理审计日志的存储逻辑本项目包含以下主要组件:
AuditLog: 审计日志实体EntityChange: 实体变更记录EntityPropertyChange: 实体属性变更记录AuditLogAction: 审计日志操作AuditLogExcelFile: 审计日志Excel文件IAuditLogRepository: 审计日志仓储接口IAuditLogExcelFileRepository: 审计日志Excel文件仓储接口IAuditingStore: 审计存储接口AuditingStore: 审计存储实现IAuditLogInfoToAuditLogConverter: 审计日志信息转换器接口AuditLogInfoToAuditLogConverter: 审计日志信息转换器实现AuditLogConstants: 审计日志常量EntityChangeConstants: 实体变更常量EntityPropertyChangeConstants: 实体属性变更常量AuditLogActionConstants: 审计日志操作常量AuditLogExcelFileConstants: 审计日志Excel文件常量AuditLogEntityTypeFullNameConverter: 审计日志实体类型全名转换器SparkdoAuditLoggingDomainModule: 审计日志领域模块配置所有公共接口和类都添加了详细的 XML 文档注释,便于开发者理解和使用。