Services: Audit, Logging & Telemetry
Shared telemetry pipeline powering BeepAudit, BeepLog, and BeepService extensions with enrichment, redaction, sampling, rate-limiting, and cross-platform sinks
Source files
DataManagementEngineStandard/Services/Audit/(BeepAudit, NullBeepAudit, Integrity, Purge, Query)DataManagementEngineStandard/Services/Logging/(BeepLog, NullBeepLog, Levels, ScopeExtensions)DataManagementEngineStandard/Services/Telemetry/(Pipeline, Sinks, Samplers, Redaction, RateLimit)DataManagementEngineStandard/Services/BeepServiceExtensions.*.cs(7 extension files)
Table of Contents
Architecture
TelemetryPipeline (shared orchestrator)
└── BoundedChannelQueue (backpressure-aware)
└── BatchWriter (fan-out to sinks)
BeepLog (IBeepLog) ───────────────┐
BeepAudit (IBeepAudit) ────────────┤──→ TelemetryPipeline ──→ Sinks
Extensions (Audit/Log/Diagnostics) ┘
Pipeline stages (per envelope):
1. Enricher → add correlation/context
2. Deduper → suppress duplicates
3. Sampler → probabilistic/rate-based sampling
4. Redactor → PII/secret scrubbing
5. RateLimiter → token bucket throttling
6. BatchWriter → fan-out to sinks
TelemetryPipeline
Shared, opt-in telemetry orchestrator backing both BeepLog and BeepAudit:
public sealed partial class TelemetryPipeline : IAsyncDisposable
{
private readonly BoundedChannelQueue _queue;
private readonly BatchWriter _writer;
private readonly IReadOnlyList<ITelemetrySink> _sinks;
private readonly IReadOnlyList<IEnricher> _enrichers;
private readonly IReadOnlyList<IRedactor> _redactors;
private readonly IReadOnlyList<ISampler> _samplers;
private readonly IMessageDeduper _deduper;
private readonly IRateLimiter _rateLimiter;
public event Action<string, Exception> SinkErrored;
// Submit an envelope to the pipeline
public ValueTask SubmitAsync(TelemetryEnvelope envelope);
// Graceful shutdown
public ValueTask FlushAsync(CancellationToken token);
}
Pipeline Stages
| Stage | Interface | Description |
|---|---|---|
| Enrichment | IEnricher | Add correlation IDs, host metadata, timestamps |
| Deduplication | IMessageDeduper | Suppress duplicate log entries |
| Sampling | ISampler | Probabilistic or rate-based decision |
| Redaction | IRedactor | Scrub PII, secrets, sensitive fields |
| Rate Limiting | IRateLimiter | Token bucket throttling per source |
| Batching | BatchWriter | Fan-out to registered sinks |
Backpressure Modes
public enum BackpressureMode { Drop, Block, Throw }
BeepAudit
Audit recorder with tamper-evidence, GDPR purge, and compliance querying:
public sealed partial class BeepAudit : IBeepAudit
{
public BeepAudit(BeepAuditOptions options,
TelemetryPipeline pipeline, IHashChainSigner signer = null);
// Record an audit event
public ValueTask RecordAsync(string action, string actor,
string resource, Dictionary<string, object> metadata);
// Compliance services (Phase 10)
public void AttachComplianceServices(
IAuditQueryEngine queryEngine = null,
GdprPurgeService purgeService = null,
IntegrityVerifier integrityVerifier = null);
// Tamper-evidence (hash chain)
public bool VerifyIntegrity(string entryId);
}
public class BeepAuditOptions
{
public bool Enabled { get; set; } = false;
public bool HashChain { get; set; } = false;
public RetentionOptions Retention { get; set; }
}
Partial Files
| File | Responsibility |
|---|---|
BeepAudit.Core.cs | ctor, RecordAsync, AttachComplianceServices |
BeepAudit.Lifetime.cs | Flush, Dispose semantics |
BeepAudit.Query.cs | Query, purge, verify stubs |
NullBeepAudit.cs | No-op when disabled |
Sub-components
| Directory | Purpose |
|---|---|
Integrity/ | Hash chain signing and tamper verification |
Purge/ | GDPR-compliant data purging |
Query/ | Audit event querying and export |
Export/ | Compliance export formats |
Bridges/ | Integration with legacy subsystems |
BeepLog
Structured logging with severity levels, scopes, and filtering:
public sealed partial class BeepLog : IBeepLog
{
public BeepLog(BeepLoggingOptions options, TelemetryPipeline pipeline);
public bool IsEnabled { get; }
public BeepLogLevel MinLevel { get; }
// Core logging
public void Log(BeepLogLevel level, string message,
Dictionary<string, object> extra = null);
// Extension methods (via BeepLogScopeExtensions)
public void Trace(string msg);
public void Debug(string msg);
public void Info(string msg);
public void Warn(string msg);
public void Error(string msg, Exception ex = null);
public void Critical(string msg, Exception ex = null);
}
public enum BeepLogLevel { Verbose, Debug, Information, Warning, Error, Critical }
public class BeepLoggingOptions
{
public bool Enabled { get; set; } = false;
public BeepLogLevel MinLevel { get; set; } = BeepLogLevel.Information;
}
Sinks & Processing
| Component | Purpose |
|---|---|
ITelemetrySink | Destination for telemetry (file, console, database) |
BatchWriter | Fan-out to multiple sinks with error isolation |
BoundedChannelQueue | Backpressure-aware queue |
IEnricher | Add metadata (correlation ID, host, timestamp) |
IRedactor | PII/secret scrubbing |
ISampler | Probabilistic sampling |
IRateLimiter | Token bucket throttling |
NdjsonSerializer | Newline-delimited JSON serialization |
Retention/ | Log rotation, compression, budgeting |
Diagnostics/ | Pipeline health and self-observability |
Service Extensions
| Extension File | Purpose |
|---|---|
BeepServiceExtensions.Audit.cs | AddBeepAudit() — registers BeepAudit |
BeepServiceExtensions.Logging.cs | AddBeepLogging() — registers BeepLog |
BeepServiceExtensions.Diagnostics.cs | Diagnostics configuration |
BeepServiceExtensions.Maui.cs | MAUI platform setup |
BeepServiceExtensions.Retention.cs | Log retention policies |
ServiceCollectionExtensions.cs | General DI extensions |
ServiceHelper.cs | Service resolution helpers |
Usage Examples
Setup Audit and Logging
var builder = Host.CreateApplicationBuilder();
// Bootstrap BeepDM itself
IBeepService beep = builder.Services.AddBeepServices()
.WithDirectory(AppContext.BaseDirectory)
.WithAppRepo("MyApp")
.WithConfigType(BeepConfigType.Application)
.AsSingleton()
.Build();
// Add audit with tamper-evidence.
// NOTE: Enabled defaults to false - both pipelines are opt-in.
builder.Services.AddBeepAudit(auditOpts =>
{
auditOpts.Enabled = true;
auditOpts.HashChain = true; // default true
auditOpts.RetentionDays = 365;
});
// Add structured logging
builder.Services.AddBeepLogging(logOpts =>
{
logOpts.Enabled = true;
logOpts.MinLevel = BeepLogLevel.Information;
});
var host = builder.Build();
Platform presets. Instead of the two generic calls above, a desktop app can
use
AddBeepLoggingForDesktop("MyApp") and
AddBeepAuditForDesktop("MyApp"), which pick platform-appropriate storage paths
and still accept a tweak delegate over the same options objects. Equivalents
exist for Web, Blazor and MAUI — see
BeepService → Service Extensions.
There is no
AddBeepForDesktop. An earlier revision of this
sample called it; that method does not exist in the codebase. Bootstrap with
AddBeepServices() as shown. Likewise RetentionOptions is not a
real type — audit retention is set via the RetentionDays int or the
Retention RetentionPolicy object.
Recording Audit Events
var audit = serviceProvider.GetRequiredService<IBeepAudit>();
await audit.RecordAsync("PipelineModified", "admin",
"customer-sync",
new Dictionary<string, object>
{
["OldBatchSize"] = 100,
["NewBatchSize"] = 500,
["Timestamp"] = DateTime.UtcNow
});
// Verify integrity
bool valid = audit.VerifyIntegrity("entry-id-123");
Structured Logging
var log = serviceProvider.GetRequiredService<IBeepLog>();
log.Info("Pipeline started");
log.Debug($"Batch size: {config.BatchSize}");
try
{
await pipeline.ExecuteAsync();
log.Info("Pipeline completed successfully");
}
catch (Exception ex)
{
log.Error("Pipeline failed", ex);
log.Critical("Pipeline critical failure - data may be inconsistent", ex);
}