Roslyn analyzer to enforce structured logging governance for CerbiStream apps. Ensures consistency, traceability, and compliance with score shipping support.
$ dotnet add package CerbiStream.GovernanceAnalyzerThis README focuses on how this library works technically and how to use it inside your own solutions. For a mixed business/technical overview and a CerbiSuite/Cerbi.io pitch, see the root README.md in this repo.
CerbiStream.GovernanceAnalyzer is the Roslyn analyzer and governance helper library that:
GovernanceConfigLoader, GovernanceHelper);It is designed to be:
Cerbi.Governance.Runtime, Cerbi.MEL.Governance, CerbiStream);Profiles live in JSON files (typically cerbi_governance.json) and define:
LoggingProfiles – keyed by profile name (PIILog, AuditLog, etc.).FieldSeverities – Required, Forbidden, Warning, Info.FieldTypes – expected types like Guid, string, int, etc.FieldEnums – whitelists for enum‑like string fields.EncryptionSettings – required/forbidden encryption modes.AllowRelax – whether relaxation is allowed (GovernanceRelaxed = true).These are Cerbi.Governance.Core models. The analyzer and helpers never invent their own types; they reuse the shared governance contracts.
GovernanceConfigLoader is the single entry point for profile loading inside the analyzer/runtime combo:
CerbiGovernance.Encryption → EncryptionSettings).LogProfile objects.TryGetProfile(string profileName, out LogProfile profile)GetAllowedLevels(string profileName)CurrentMode (Permissive, WarnOnly, Strict).LogGovernanceAnalyzer (and related analyzers) inspect log invocations such as:
logger.LogInformation("User {userId} logged in", userId);
The analyzer will:
{userId} from the message template.PIILog).FieldSeverities["userId"] and type rules.password),Region not in ["US","EU"]),userId string vs Guid),The diagnostics plug into standard Roslyn infrastructure and are consumable by IDEs and CI.
dotnet add package CerbiStream.GovernanceAnalyzer
{
"EnforcementMode": "Strict",
"LoggingProfiles": {
"PIILog": {
"AllowRelax": false,
"AllowedLevels": ["Information", "Error"],
"FieldSeverities": {
"userId": "Required",
"password": "Forbidden"
},
"FieldTypes": {
"userId": "Guid"
},
"FieldEnums": {
"Region": ["US", "EU"]
},
"EncryptionSettings": {
"Mode": "AES",
"FieldSeverity": "Required"
}
}
}
}
Place this file in your app (default: ./cerbi_governance.json or config/cerbi_governance.json).
using Cerbi.Governance;
[assembly: CerbiGovernanceConfig("config/cerbi_governance.json")]
When a developer writes something that violates the profile, such as:
logger.LogInformation("Login {userId} with password {password}", userId, password);
you’ll see analyzer diagnostics like:
password),These diagnostics behave like any other Roslyn analyzer warning/error.
Although this library is analyzer‑centric, the repo also includes runtime helpers that support CerbiStream and Cerbi.MEL.Governance:
Runtime/CerbiGovernanceLogger.cs – wraps MEL loggers and applies governance.Runtime/GovernanceScoreShipper.cs – channel‑based, high‑throughput shipper for PII‑safe scoring metadata.Extensions/CerbiGovernanceBuilder.cs – fluent API for configuring governance + score shipping via ILoggingBuilder.Example (conceptual):
builder.Logging.AddCerbiGovernance(cerbi => cerbi
.WithConfigFile("cerbi_governance.json")
.UseProfile("PIILog")
.WithBalancedScoreShipping("https://api.cerbi.io/scores", licenseKey));
This path is mostly exercised by the runtime NuGet packages, but the implementation lives here so analyzers and runtime share a codebase.
This library is part of the CerbiSuite governance story described on https://cerbi.io:
For a sales/exec oriented explanation (log spend reduction, redaction posture, dashboard stability, etc.) see the site and the root repo README.md. This file is intentionally focused on how to integrate and extend the analyzer and helpers in code.
If you want to extend the analyzers:
LogGovernanceAnalyzer.cs and test files under CerbiStream.GovernanceAnalyzer-Tests;Cerbi.Governance.Core models wherever possible;If you want to modify runtime pieces (shipper, builder, logger providers), ensure:
PRODUCTION_READY_SUMMARY.md and THROUGHPUT_ANALYSIS.md.