CerbiStream 1.0.15

There is a newer version of this package available.
See the version list below for details.
dotnet add package CerbiStream --version 1.0.15
                    
NuGet\Install-Package CerbiStream -Version 1.0.15
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CerbiStream" Version="1.0.15" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CerbiStream" Version="1.0.15" />
                    
Directory.Packages.props
<PackageReference Include="CerbiStream" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CerbiStream --version 1.0.15
                    
#r "nuget: CerbiStream, 1.0.15"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=CerbiStream&version=1.0.15
                    
Install CerbiStream as a Cake Addin
#tool nuget:?package=CerbiStream&version=1.0.15
                    
Install CerbiStream as a Cake Tool

CerbiStream: Dev-Friendly Logging for .NET

NuGet Downloads License .NET

Dev Friendly Governance Enforced

Cerbi CI Quality Gate

πŸš€ View CerbiStream Benchmarks

Compare against Serilog, NLog, and others. CerbiStream is tuned for performance, governance, and enterprise-scale routing.


βœ… Highlights

  • Works with ILogger<T> out of the box
  • Structured logging enforcement via CerbiStream or GovernanceAnalyzer
  • Fully supports RabbitMQ, Kafka, Azure Service Bus, AWS SQS/Kinesis, GCP Pub/Sub
  • Flexible encryption: None, Base64, AES (configurable)
  • Optional Roslyn-based GovernanceAnalyzer or external validator hook
  • πŸ” Queue-first architecture (sink-agnostic, logs route through CerbIQ if desired)
  • Entity Framework and Blazor-friendly via external governance validator option

πŸ”„ External Governance Hook If you're not using the CerbiStream.GovernanceAnalyzer package (e.g., to avoid Roslyn dependency issues with Entity Framework or Blazor), you can provide your own governance validation logic:

options.WithGovernanceValidator((profile, data) =>
{
    // Custom governance validation logic
    return data.ContainsKey("UserId") && data.ContainsKey("IPAddress");
});

This lets you enforce structure without referencing Roslyn, making CerbiStream fully compatible with EF Core and other analyzers.


✨ What's New in v1.0.11

  • New presets: BenchmarkMode(), EnableDeveloperModeWithTelemetry()
  • Toggle: telemetry, console, metadata, governance
  • JSON conversion with encryption
  • Queue routing using enums

🧰 Install

dotnet add package CerbiStream

Optional governance analyzer:

dotnet add package CerbiStream.GovernanceAnalyzer

⚑ Quick Start

builder.Logging.AddCerbiStreamWithRouting(options =>
{
    options.WithQueue("RabbitMQ", "localhost", "logs-queue")
           .EnableDeveloperModeWithoutTelemetry()
           .WithEncryptionMode(EncryptionType.Base64);
});

Configuration Setup Guide

CerbiStream is a structured logging framework designed for observability, telemetry enrichment, and governance enforcement. This guide demonstrates how to configure CerbiStreamOptions using the available setup methods.

πŸ”§ Basic Setup

builder.Logging.AddCerbiStream(options =>
{
    options.EnableDevModeMinimal(); // Logs only to console, minimal metadata
});

βš™οΈ Available Preset Modes

βœ… EnableDevModeMinimal()

Minimal output, console only, no metadata injection, ideal for simple development scenarios.

options.EnableDevModeMinimal();

βœ… EnableDeveloperModeWithoutTelemetry()

Includes basic metadata injection but skips telemetry logging.

options.EnableDeveloperModeWithoutTelemetry();

βœ… EnableDeveloperModeWithTelemetry()

Enables metadata injection, console output, and sends to telemetry.

options.EnableDeveloperModeWithTelemetry();

βœ… EnableBenchmarkMode()

Disables all outputs and features for benchmarking.

options.EnableBenchmarkMode();

πŸ›  Custom Configuration

Set Custom Queue

options.WithQueue("RabbitMQ", "localhost", "my-logs");

Set Encryption Mode

options.WithEncryptionMode(EncryptionType.Base64);
options.WithEncryptionKey(keyBytes, ivBytes);

Enable or Disable Features

options.WithTelemetryLogging(true);
options.WithConsoleOutput(true);
options.WithMetadataInjection(true);
options.WithTelemetryEnrichment(true);
options.WithGovernanceChecks(true);
options.WithDisableQueue(false);

🧠 Add Advanced Metadata

options.WithAdvancedMetadata(true);
options.WithSecurityMetadata(true);

πŸ§ͺ External Governance Validator

options.WithGovernanceValidator((profile, log) =>
{
    // Custom validation logic
    return log.ContainsKey("requiredKey");
});

πŸ” Mode Detection

You can check the runtime mode using:

bool isMinimal = options.IsMinimalMode;
bool isBenchmark = options.IsBenchmarkMode;

πŸ“Œ Note: These methods are chainable, allowing fluent configuration:

builder.Logging.AddCerbiStream(options =>
{
    options.WithQueue("RabbitMQ", "localhost", "audit-logs")
           .WithConsoleOutput(true)
           .WithGovernanceChecks(true);
});

πŸ”Ή EnableDevModeMinimal()

Purpose: Quickly enables console logging with minimal features for local development or container diagnostics.

  • βœ… Console Output: true
  • ❌ Telemetry Enrichment: false
  • ❌ Metadata Injection: false
  • ❌ Governance Checks: false
  • ❌ Queue Sending: enabled
  • βœ… Best for: Minimal test containers, low-overhead logging in dev

Example:

builder.Logging.AddCerbiStream(options => options.EnableDevModeMinimal());

πŸ”Ή EnableDeveloperModeWithoutTelemetry()

Purpose: Enables local developer logging without external telemetry.

  • βœ… Console Output: true
  • βœ… Metadata Injection: true
  • ❌ Telemetry Enrichment: false
  • ❌ Governance Checks: false

Example:

builder.Logging.AddCerbiStream(options => options.EnableDeveloperModeWithoutTelemetry());

πŸ”Ή EnableDeveloperModeWithTelemetry()

Purpose: Enables all developer logging features including telemetry, for full context during dev work.

  • βœ… Console Output: true
  • βœ… Metadata Injection: true
  • βœ… Telemetry Enrichment: true
  • ❌ Governance Checks: false

Example:

builder.Logging.AddCerbiStream(options => options.EnableDeveloperModeWithTelemetry());

πŸ”Ή EnableBenchmarkMode()

Purpose: Disables all overhead logging features, ideal for performance benchmarking.

  • ❌ Console Output: false
  • ❌ Metadata Injection: false
  • ❌ Telemetry Enrichment: false
  • ❌ Governance Checks: false
  • βœ… Queue Sending: disabled

Example:

builder.Logging.AddCerbiStream(options => options.EnableBenchmarkMode());

πŸ” Runtime Encryption

options.WithEncryptionMode(EncryptionType.AES)
       .WithEncryptionKey(myKey, myIV);

Default (lazy) test keys:

var (key, iv) = EncryptionHelpers.GetInsecureDefaultKeyPair();
options.WithEncryptionKey(key, iv);

KeyVault example:

var key = Convert.FromBase64String(await secretClient.GetSecret("CerbiKey"));
var iv = Convert.FromBase64String(await secretClient.GetSecret("CerbiIV"));

πŸ› οΈ Preset Modes

Method Description
EnableDeveloperModeWithTelemetry() Console + telemetry + metadata
EnableDeveloperModeWithoutTelemetry() Console + metadata, no telemetry
EnableDevModeMinimal() Console only
EnableBenchmarkMode() Silent mode (no telemetry, queue, or console)

πŸ” Retry Example

Policy
  .Handle<Exception>()
  .WaitAndRetry(3, _ => TimeSpan.FromSeconds(1), (ex, _, attempt, _) =>
  {
      TelemetryContext.IsRetry = true;
      TelemetryContext.RetryAttempt = attempt;
  });

πŸ”§ Configuration Options

Option Description
.WithQueue(...) Configure queue host, name, and type
.DisableQueue() Stops sending logs to queues
.WithTelemetryProvider() Set custom telemetry provider
.IncludeSecurityMetadata() Adds IP/UserID info
.EnableTelemetryLogging() Sends to telemetry even if queue is disabled

πŸ“Š Telemetry Provider Support

Provider Supported
OpenTelemetry βœ…
Azure App Insights βœ…
AWS CloudWatch βœ…
GCP Trace βœ…
Datadog βœ…

πŸ“˜ Code Samples

CerbiLoggerBuilder

var logger = new CerbiLoggerBuilder()
    .UseAzureServiceBus("<conn>", "<queue>")
    .EnableDebugMode()
    .Build(logger, new ConvertToJson(), new NoOpEncryption());

Fluent API

var options = new CerbiStreamOptions()
    .WithEncryptionMode(EncryptionType.Base64)
    .WithQueue("RabbitMQ", "localhost", "logs");

AddCerbiStreamWithRouting (DI)

builder.Logging.AddCerbiStreamWithRouting(options =>
{
    options.WithQueue("AzureServiceBus", "sb://...", "queue")
           .WithEncryptionMode(EncryptionType.AES);
});

πŸ§ͺ Unit Test Example

var mockQueue = Substitute.For<IQueue>();
var logger = new Logging(Substitute.For<ILogger<Logging>>(), mockQueue, new ConvertToJson(), new NoOpEncryption());

var result = await logger.LogEventAsync("Test", LogLevel.Information);
Assert.True(result);

🌐 Supported Queues

  • RabbitMQ
  • Kafka
  • Azure Queue / Service Bus
  • AWS SQS / Kinesis
  • Google Pub/Sub

🧡 Queue-First Logging (Sink-Agnostic)

CerbiStream does not directly send logs to sinks like Splunk, Elastic, or Blob.

Instead:

  • πŸ” Logs are emitted to queues only (Kafka, RabbitMQ, Azure, etc.)
  • 🧠 CerbIQ reads from these queues and sends logs to sinks
  • βœ… Keeps log generation decoupled from log delivery

This design gives you:

  • Better performance
  • Retry-friendly resilience
  • Pluggable downstream integrations

➑️ Add CerbIQ to handle routing and sink delivery.


πŸ” Governance Enforcement (Optional)

{
  "LoggingProfiles": {
    "SecurityLog": {
      "RequiredFields": ["UserId", "IPAddress"],
      "OptionalFields": ["DeviceType"]
    }
  }
}

πŸ“œ License

MIT


Star the repo ⭐ β€” Contribute πŸ”§ β€” File issues πŸ›

Created by @Zeroshi

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.1 165 4/13/2025
1.1.0 163 4/13/2025
1.0.16 128 4/10/2025
1.0.15 126 4/7/2025
1.0.14 78 4/6/2025
1.0.13 102 3/28/2025
1.0.12 95 3/27/2025
1.0.11 430 3/26/2025
1.0.10 451 3/25/2025
1.0.9 126 3/23/2025
1.0.8 42 3/22/2025
1.0.7 106 3/21/2025
1.0.6 116 3/20/2025
1.0.5 118 3/20/2025
1.0.4 111 3/19/2025
1.0.3 110 3/19/2025
1.0.2 129 3/12/2025
1.0.1 119 3/12/2025