Skip to content

InMemoryAuditLog

Namespace AgentPrism · Assembly AgentPrism.Core.dll

An audit log that keeps entries in process memory.

public sealed class InMemoryAuditLog : IAuditLog

objectInMemoryAuditLog

IAuditLog

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Use AgentPrism.PostgreSql in production.

The hash chain is computed here too: entries are kept per tenant (ConcurrentDictionary<string, List<AuditEntry>>) and each tenant’s list is locked for its own read-last-hash/compute/append sequence — a single process has no cross-connection writer race the way a SQL provider does, so a lock (not a retry loop) is enough. Locking ON THE LIST ITSELF (rather than a dedicated lock field) is deliberate: net8.0 is also targeted and System.Threading.Lock arrived only with.NET 9 — the same pattern RunTraceCollector.RunSpanBuffer uses.

public InMemoryAuditLog()

QueryAsync(AuditQuery, CancellationToken)

Section titled “ QueryAsync(AuditQuery, CancellationToken)”

Reads the records through a filter.

public ValueTask<IReadOnlyList<AuditEntry>> QueryAsync(AuditQuery query, CancellationToken cancellationToken = default)

query AuditQuery

The filter.

cancellationToken CancellationToken

The cancellation token.

ValueTask<IReadOnlyList<AuditEntry>>

The records, newest first.

VerifyChainAsync(AuditChainQuery, CancellationToken)

Section titled “ VerifyChainAsync(AuditChainQuery, CancellationToken)”

Walks a tenant’s hash chain and reports whether it is intact.

public ValueTask<AuditChainVerification> VerifyChainAsync(AuditChainQuery query, CancellationToken cancellationToken = default)

query AuditChainQuery

The scope: tenant and, optionally, a date range.

cancellationToken CancellationToken

The cancellation token.

ValueTask<AuditChainVerification>

The verification result.

A date range narrows which entries are walked; it does not weaken the check within that range. Because the entry immediately before the range’s start is not read, a break at the range’s own boundary cannot be judged and is not reported — an unbounded query is the only way to check a tenant’s whole history.

WriteAsync(AuditEntry, CancellationToken)

Section titled “ WriteAsync(AuditEntry, CancellationToken)”

Writes an audit record.

public ValueTask WriteAsync(AuditEntry entry, CancellationToken cancellationToken = default)

entry AuditEntry

The record to write.

cancellationToken CancellationToken

The cancellation token.

ValueTask