Guides & Recipes — Auditing
Production recipes for querying large tenant audit logs with keyset continuation tokens and verifying cryptographic chains.
Recipe 1: Keyset Cursor Pagination with ContinuationToken
Section titled “Recipe 1: Keyset Cursor Pagination with ContinuationToken”v2.0.0 replaced integer/ID cursor properties (AfterRecordId / NextCursorId) with opaque ContinuationToken and NextPageToken:
using System.Collections.Generic;using System.Threading;using System.Threading.Tasks;using EricksonLopez.Auditing;
namespace Example.AuditingRecipes;
public static class AuditLogReader{ public static async Task<IReadOnlyList<AuditRecord>> ReadAllForOrderAsync( IAuditStore store, string tenantId, string orderId, CancellationToken ct) { var collected = new List<AuditRecord>(); string? token = null;
do { AuditQueryResult page = await store.QueryAsync(new AuditQuery { TenantId = new TenantId(tenantId), ResourceType = "Order", ResourceId = orderId, PageSize = 100, ContinuationToken = token }, ct);
collected.AddRange(page.Records); token = page.HasMore ? page.NextPageToken : null; } while (token is not null);
return collected; }}Recipe 2: Streaming Large Exports with StreamAsync
Section titled “Recipe 2: Streaming Large Exports with StreamAsync”For compliance exports that exceed single-page memory budgets, iterate await foreach (AuditRecord entry in store.StreamAsync(query, ct)) to stream rows directly from the underlying provider cursor without materializing all pages in memory.
Recipe 3: Batch Ingestion with AppendBatchAsync
Section titled “Recipe 3: Batch Ingestion with AppendBatchAsync”When recording bulk administrative actions (e.g., permission sweeps), group records into an IReadOnlyList<AuditRecord> and call await store.AppendBatchAsync(batch, ct) so providers execute a single round-trip while preserving per-tenant chain order.