Skip to content

Search EricksonLopez.* Ecosystem

Type a library name, NuGet package ID, .NET type, or architectural concept to search across the portal.

Core Concepts — AuditRecord, TenantId & Integrity Chain

EricksonLopez.Auditing models every audit entry as an immutable event record bound to an explicit tenant boundary and optional cryptographic chain.

AuditRecord is a sealed record enforcing required structural fields (Id, OccurredAt, Actor, Action, Resource, Outcome, Context) alongside optional Changes, ErrorCode, IntegrityHash, and PreviousHash:

  • AuditId.NewId(): Generates a time-ordered UUIDv7 Guid for sequential primary-key locality in B-tree database indexes.
  • AuditRecordBuilder: Fluent builder validating actor, action, resource, and outcome invariants while pulling ambient AuditScope values automatically (TenantId, CorrelationId, metadata).
  • Length guardrails (v2.0.0): Strings exceeding MaxStringLength are truncated deterministically before persistence.

Since v2.0.0 (BC-001–BC-003), AuditContext, AuditQuery, and IAuditIntegrityProvider enforce TenantId instead of raw strings:

  • TenantId wraps a non-empty trimmed tenant identifier (ArgumentException.ThrowIfNullOrWhiteSpace) with implicit conversions to and from string.
  • SystemTenantId is a static readonly TenantId (changed from const string in v2.0.0).
  • AuditScope.Begin() stores ambient context in AsyncLocal<T> and restores the outer scope cleanly on Dispose().

HmacAuditIntegrityService computes each record’s IntegrityHash over length-prefixed UTF-8 field encodings (v2.0.0 BC-006) plus the tenant’s previous IntegrityHash:

  • Length-prefix framing prevents canonicalization ambiguity when field values contain delimiter characters.
  • Database providers index (tenant_id, previous_hash) and support idempotency_key deduplication to prevent chain forks under concurrent retries.
  • IAuditStore exposes AppendAsync, AppendBatchAsync, cursor-based QueryAsync(AuditQuery) (ContinuationToken / NextPageToken), and StreamAsync(AuditQuery).