CerbiStream.GovernanceAnalyzer 1.1.4

dotnet add package CerbiStream.GovernanceAnalyzer --version 1.1.4
                    
NuGet\Install-Package CerbiStream.GovernanceAnalyzer -Version 1.1.4
                    
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.GovernanceAnalyzer" Version="1.1.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CerbiStream.GovernanceAnalyzer" Version="1.1.4" />
                    
Directory.Packages.props
<PackageReference Include="CerbiStream.GovernanceAnalyzer" />
                    
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.GovernanceAnalyzer --version 1.1.4
                    
#r "nuget: CerbiStream.GovernanceAnalyzer, 1.1.4"
                    
#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.GovernanceAnalyzer&version=1.1.4
                    
Install CerbiStream.GovernanceAnalyzer as a Cake Addin
#tool nuget:?package=CerbiStream.GovernanceAnalyzer&version=1.1.4
                    
Install CerbiStream.GovernanceAnalyzer as a Cake Tool

CerbiStream Governance Analyzer

NuGet NuGet Downloads License: MIT .NET


πŸ›‘οΈ CerbiStream Governance Analyzer

CerbiStream-GovernanceAnalyzer is a high-performance, plugin-extensible governance engine for structured logging in .NET. It enables both runtime enforcement and compile-time analysis (via Roslyn Analyzer) to ensure logging consistency, security, and observability compliance.


βœ… What’s New?

  • πŸ”„ Live Reloading of JSON governance configs
  • 🧠 Plugin Architecture β€” inject dynamic validation rules (per environment, compliance, etc.)
  • 🧩 Per-field Type & Enum Enforcement
  • 🚫 DisallowedFields Support β€” prevent sensitive or restricted data from being logged
  • πŸ” Governance Modes: Permissive, WarnOnly, Strict
  • πŸ“Š Impact Scoring for governance violations (coming soon)
  • πŸ” Roslyn Analyzer to catch issues at build-time

πŸ“¦ Installation

dotnet add package CerbiStream.GovernanceAnalyzer

---CerbiStream-GovernanceAnalyzer is a Roslyn-based static analysis tool designed to enforce structured logging standards within applications using CerbiStream. It ensures that log messages adhere to governance rules defined in JSON configurations, reducing runtime validation overhead and improving developer experience.

πŸ”₯ Why Use CerbiStream-GovernanceAnalyzer?

  • Compile-Time Log Validation – Prevents misformatted logs before deployment.
  • Structured Logging Enforcement – Ensures consistent log structures across teams.
  • Customizable Rules via JSON – Allows organizations to define mandatory fields for logs.
  • Seamless Integration with CerbiStream – Works alongside CerbiStream for log governance.
  • Lightweight & Fast – Runs at build time, avoiding runtime performance impact.

πŸš€ Installation

To add CerbiStream-GovernanceAnalyzer to your project, install it via NuGet:

 dotnet add package CerbiStream.GovernanceAnalyzer

Or update your .csproj:

<ItemGroup>
    <PackageReference Include="CerbiStream.GovernanceAnalyzer" Version="1.0.0" />
</ItemGroup>

πŸ“Œ How It Works

  1. Governance Rules via JSON

    • Define required and optional logging fields in a cerbi_governance.json file.
    • Example:
    {
       "LoggingProfiles": {
           "Default": {
               "RequiredFields": ["Timestamp", "LogLevel", "Message", "ApplicationId"],
               "OptionalFields": ["UserId", "TransactionId"]
           }
       }
    }
    
  2. Static Analysis at Build-Time

    • The analyzer verifies that logs match the governance profile during compilation.
    • Example of a valid log:
    logger.LogInformation("User login successful | UserId: {UserId}, Timestamp: {Timestamp}", userId, DateTime.UtcNow);
    
    • Example of an invalid log (missing required fields):
    logger.LogInformation("User login successful"); // ❌ Missing required metadata
    
    • The build will fail with a warning/error indicating missing required fields.
  3. Enforce or Warn Mode

    • Choose whether governance rules should fail the build (Error Mode) or just warn developers (Warning Mode).
    • This can be controlled via the cerbi_governance.json file.

πŸ› οΈ Configuration Options

Option Type Description
RequiredFields string[] Fields that must be present in logs.
OptionalFields string[] Fields that are recommended but not mandatory.
EnforcementLevel string Can be Error (fail build) or Warning (notify devs).

πŸ“– Example Usage

1️⃣ Enabling Governance in CerbiStream

In your Program.cs:

var serviceProvider = new ServiceCollection()
    .AddLogging(builder =>
    {
        builder.AddCerbiStream(options =>
        {
            options.EnableGovernance();
        });
    })
    .BuildServiceProvider();

2️⃣ Running the Governance Analyzer

The analyzer automatically runs during the build process. If any logs do not meet governance standards, you’ll see build errors or warnings.

🎯 Future Enhancements

  • Integration with CI/CD Pipelines – Enforce logging rules in GitHub Actions/Azure DevOps.
  • Dashboard for Governance Management – UI to configure log governance dynamically.
  • Multi-Project Support – Apply governance rules across microservices.

πŸ“œ License

CerbiStream-GovernanceAnalyzer is open-source under the MIT License.

πŸ“¬ Contact & Contributions

We welcome contributions! Submit an issue or a pull request on GitHub.


🧰 Runtime Usage

πŸ”§ 1. Governance Config Example

{
{
  "Version": "1.0",
  "EnforcementMode": "Strict",
  "LoggingProfiles": {
    "API": {
      "RequiredFields": ["Timestamp", "LogLevel", "Message", "ApplicationId"],
      "OptionalFields": ["UserId", "TransactionId"],
      "DisallowedFields": ["ssn", "creditCardNumber", "socialSecurityNumber"],
      "AllowedLevels": ["Information", "Warning", "Error"],
      "Encryption": "None",
      "FieldTypes": {
        "ApplicationId": "Guid"
      },
      "FieldEnums": {
        "Environment": ["Development", "Staging", "Production"]
      }
    }
  }
}


πŸ›  How to Use

GovernanceConfigLoader.SetGovernanceFilePath("config/cerbi_governance.json");
var isValid = GovernanceHelper.TryValidate("PIILog", logData, out var errors);

πŸ“„ Requires a governance config file. See config/cerbi_governance.json for format.

βœ… Summary

Feature Status
Governance rules loaded at runtime βœ… Ready
Profile validation logic βœ… Modular + extensible
Multi-profile support βœ… Aligned to schema
File-based config (no API calls) βœ… Lightweight + secure
Project structure βœ… Enterprise-friendly

πŸ§ͺ 2. Validate a Log Entry at Runtime

var logData = new Dictionary<string, object>
{
    { "Timestamp", DateTime.UtcNow },
    { "LogLevel", "Error" },
    { "Message", "Order failed" },
    { "ApplicationId", Guid.NewGuid() }
};

var valid = GovernanceHelper.TryValidate("API", logData, out var errors);

if (!valid)
{
    Console.WriteLine("Governance violations:");
    errors.ForEach(Console.WriteLine);
}

❌ Disallowed Fields

You can now explicitly block fields that must not appear in any log entry. This helps enforce compliance with security, privacy, or internal data handling policies (e.g., GDPR, HIPAA).

πŸ“„ Governance Config Example
{
  "LoggingProfiles": {
    "PIILog": {
      "RequiredFields": ["Timestamp", "Message", "UserId"],
      "DisallowedFields": ["SSN", "CreditCardNumber", "MedicalRecordId"],
      "AllowedLevels": ["Information", "Error"]
    }
  }
}

🧩 Flat JSON-Only Governance Mode

CerbiStream.GovernanceAnalyzer uses a single, flat JSON file for rule configuration.

πŸ“˜ See cerbi_governance.schema.json for full validation schema used by the dashboard and Monaco Editor.

No tenants. No runtime switching. No external lookups.
Just fast, lightweight governance.

Mode Behavior
Permissive All logs accepted, violations ignored
WarnOnly Violations logged (to console or telemetry), but logs still pass
Strict Logs that violate governance are blocked or flagged

βš™οΈ Runtime Enforcement

  • πŸ”„ Live JSON reload (no restart)
  • 🧩 Plugins (validate based on environment, team, user, etc.)
  • πŸ” Field-level encryption enforcement
  • 🧠 Impact scoring (optional)

πŸ§ͺ Compile-Time Enforcement (Roslyn)

  • πŸ” Catch missing fields at build time
  • ❌ Warn on disallowed log levels
  • βœ… Extensible for IDE feedback

βœ… Example Governance Config (cerbi_governance.json)

{
  "EnforcementMode": "Strict",
  "LoggingProfiles": {
    "PIILog": {
      "RequiredFields": ["userId", "ssn"],
      "AllowedLevels": ["Information", "Error"],
      "Encryption": "AES"
    },
    "SecurityLog": {
      "RequiredFields": ["userId", "IPAddress"],
      "AllowedLevels": ["Error", "Critical"],
      "Encryption": "AES"
    }
  }
}

πŸ”Œ Governance Plugins (Extend Enforcement)

πŸ“„ Interface

public interface ICustomGovernancePlugin
{
    string Id { get; }
    string Description { get; }
    PluginCategory Category { get; }
    string[] AppliesToProfiles { get; }

    bool Validate(string profileName, Dictionary<string, object> logData, out List<string> failures, out int impactScore);
}

βš™οΈ Example Plugin

public class TeamIdPlugin : ICustomGovernancePlugin
{
    public string Id => "plugin.teamid.required";
    public string Description => "Requires TeamId when Environment = Production";
    public PluginCategory Category => PluginCategory.Security;
    public string[] AppliesToProfiles => new[] { "*" };

    public bool Validate(string profile, Dictionary<string, object> logData, out List<string> failures, out int impactScore)
    {
        failures = new();
        impactScore = 0;

        if (logData.TryGetValue("Environment", out var env) &&
            env?.ToString()?.Equals("Production", StringComparison.OrdinalIgnoreCase) == true)
        {
            if (!logData.ContainsKey("TeamId"))
            {
                failures.Add("MissingField: TeamId is required in Production");
                impactScore = 5;
                return false;
            }
        }

        return true;
    }
}

πŸ’‘ Register your plugin once on startup:

GovernancePluginManager.Plugin = new TeamIdPlugin();

πŸ§ͺ Developer Features

Feature Description
πŸ” Live JSON Reloading Picks up changes without restarting
⚠️ Roslyn Analyzer Catch missing or misused log fields at compile time
🧩 Plugin Architecture Inject your own rule logic dynamically
🧠 Impact Scoring (Optional) Rate violation severity to CerbIQ or dashboards
πŸ” Profile-Level Encryption Mark logs as "AES", "Base64", etc.
πŸ§ͺ Unit-Test Friendly Supports mocking, config switching, and override injection

πŸ’‘ Example Governance Violation

MissingField: ApplicationId
InvalidEnum: Environment must be one of [Development, Staging, Production]
InvalidType: ApplicationId expected guid

🀝 CerbiStream + Governance Analyzer

Use both for complete log compliance, structure, and real-time observability

dotnet add package CerbiStream
dotnet add package CerbiStream.GovernanceAnalyzer
  • CerbiStream handles routing, structure, and metadata
  • GovernanceAnalyzer ensures enforcement and correctness

πŸ“ Roadmap

Feature Status
πŸ”Œ Plugin Metadata + Categories βœ… Done
πŸ“Š Governance Violation Scoring βœ… Done
πŸ”§ CLI Linter for JSON / Logs πŸ”œ Planned
πŸŽ› CerbiShield Dashboard Controls πŸ”œ Planned
πŸ€– Copilot Hints + VSCode Plugin πŸ”œ Planned

πŸ“¬ Contact & Community

πŸ”– MIT Licensed Β· πŸ’¬ Built for real developers.
🧠 Structured. Secure. Governed. Fast.

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.4 43 4/19/2025
1.1.0 132 4/18/2025
1.0.5 117 3/28/2025
1.0.4 452 3/26/2025
1.0.3 148 3/23/2025
1.0.2 139 3/20/2025
1.0.1 194 3/19/2025
1.0.0 139 3/19/2025

Added plugin support, type/enum validation, severity scoring, and governance metadata. First governance milestone for enterprise adoption.