Skip to content
bitzorcas
EN

Reference

Auditing module

Comprehensive audit system — 7-category sharded storage, channel-based async pipeline, entity change tracking, retention policies, and Quartz-based cleanup jobs.

Last updated

BitzOrcas provides a 7-category audit system with sharded storage tables, an async channel-based pipeline, entity-level change tracking, and configurable retention policies.

Architecture

Request → RequestAuditMiddleware → IAuditLogger
ChannelAuditQueue
(unbounded Channel<T>)
Background AuditWriter
┌──────────────────┼──────────────────┐
▼ ▼ ▼
SysAuditLog SysActivityLog SysExternalRequestLogRecord
SysSpecialLog SysCommunicationLog SysEntityPropertyChangesLog
+ SysSpecialLog

7 audit categories

CategoryTablePurpose
GeneralSysAuditLogGeneral audit trail entries
ActivitySysActivityLogUser activity tracking
Entity Property ChangesSysEntityPropertyChangesLogField-level change tracking
CommunicationSysCommunicationLogInbound/outbound API calls
External RequestSysExternalRequestLogRecordOutbound HTTP calls with details
SpecialSysSpecialLogSpecial/sensitive events

Entity change tracking

SqlSugarEntityChangeAuditor tracks field-level changes to any entity:

{
"entityType": "NoteEntity",
"entityId": "abc123",
"changes": [
{ "property": "Title", "oldValue": "Old", "newValue": "New" },
{ "property": "Content", "oldValue": "...", "newValue": "..." }
]
}

Audit pipeline components

ComponentLocationPurpose
IAuditLoggerBitzOrcas.InfrastructureEnqueue audit entries
ChannelAuditQueueBitzOrcas.InfrastructureBackground queue processor
AuditEntryNormalizerBitzOrcas.InfrastructureNormalize/validate entries
IAuditLogStoreBitzOrcas.InfrastructurePersistence port
SqlSugarAuditLogStoreInfra.SqlSugar.AuditingSqlSugar implementation
IAuditQueryPortBitzOrcas.InfrastructureRead-only query port
IAuditRetentionPortBitzOrcas.InfrastructureRetention cleanup port
IAuditTableInitializerBitzOrcas.InfrastructureSchema init port

Sharded entity hierarchy

Audit tables use a separate entity hierarchy with built-in sharding:

AuditEntityBase (snowflake Id)
├── AuditTenantEntityBase (+ TenantId)
│ └── AuditTenantSoftDeleteEntityBase (+ IsDeleted)
│ ├── SysAuditLogEntity
│ ├── SysActivityLogEntity
│ ├── SysCommunicationLogEntity
│ ├── SysExternalRequestLogRecordEntity
│ ├── SysEntityPropertyChangesLogEntity
│ └── SysSpecialLogEntity

Retention policy

Configured via Quartz.NET in the JobHost:

{
"Audit": {
"Retention": {
"Enabled": true,
"CronExpression": "0 0 2 * * ?",
"MaxAgeDays": 90
}
}
}

AuditRetentionQuartzJob runs on the Cron schedule, calling IAuditRetentionPort.CleanupAsync() to purge records older than the retention period.

Audit exclusions

Use [AuditIgnore] attribute to exclude specific request handlers or properties from audit:

[AuditIgnore]
public class PingQueryHandler : IRequestHandler<PingQuery, Pong> { }

Audit endpoints

EndpointMethodDescription
/api/audit/logsGETPaginated audit log query
/api/audit/activityGETActivity log query
/api/audit/entity-changesGETEntity change history
/api/audit/external-requestsGETExternal request audit

See also