Cerbi.Serilog.GovernanceAnalyzer 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Cerbi.Serilog.GovernanceAnalyzer --version 1.0.0
                    
NuGet\Install-Package Cerbi.Serilog.GovernanceAnalyzer -Version 1.0.0
                    
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="Cerbi.Serilog.GovernanceAnalyzer" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Cerbi.Serilog.GovernanceAnalyzer" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Cerbi.Serilog.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 Cerbi.Serilog.GovernanceAnalyzer --version 1.0.0
                    
#r "nuget: Cerbi.Serilog.GovernanceAnalyzer, 1.0.0"
                    
#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.
#:package Cerbi.Serilog.GovernanceAnalyzer@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Cerbi.Serilog.GovernanceAnalyzer&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Cerbi.Serilog.GovernanceAnalyzer&version=1.0.0
                    
Install as a Cake Tool

Cerbi Serilog Governance Analyzer

NuGet NuGet Downloads License: MIT .NET 8.0


๐Ÿงช Compile-Time Governance for Serilog

Cerbi.Serilog.GovernanceAnalyzer is a Roslyn analyzer that validates your log statements at compile-time to ensure they meet governance policies. Whether you need to enforce required fields, block sensitive data, or maintain consistency across teams โ€” this analyzer helps shift governance left into your IDE and CI pipelines.

Disclaimer: Cerbi LLC is not affiliated with or endorsed by the maintainers of Serilog. This analyzer is a third-party tool designed to work alongside Serilog for governance enforcement.


๐Ÿ“ฆ Installation

dotnet add package Cerbi.Serilog.GovernanceAnalyzer

๐Ÿš€ Key Features

  • ๐Ÿšซ Flags missing required fields
  • ๐Ÿ”’ Prevents forbidden keys (e.g., SSN, CreditCard)
  • โš ๏ธ Warns on advisory or incorrect enum values
  • ๐Ÿ” Supports live reload of cerbi_governance.json
  • ๐Ÿงฉ Pluggable validation via ICustomGovernancePlugin

๐Ÿ”ง Setup + Usage

1๏ธโƒฃ Install Serilog and Cerbi Analyzer
dotnet add package Serilog

Already covered: dotnet add package Cerbi.Serilog.GovernanceAnalyzer

2๏ธโƒฃ Add Governance Config to Your Project

Create config/cerbi_governance.json:

{
  "EnforcementMode": "Strict",
  "LoggingProfiles": {
    "default": {
      "FieldSeverities": {
        "userId": "Required",
        "ssn": "Forbidden"
      }
    }
  }
}

Update .csproj to include:

<None Include="config\cerbi_governance.json">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
3๏ธโƒฃ Configure Serilog with Governance
using Serilog;
using Cerbi.Serilog.GovernanceAnalyzer;

Log.Logger = new LoggerConfiguration()
    .Filter.WithCerbiGovernance("config/cerbi_governance.json", "default")
    .WriteTo.Console()
    .CreateLogger();
4๏ธโƒฃ Example Log (โœ… Passes Governance)
Log.Information("User created| userId={UserId}", "abc-123");
5๏ธโƒฃ Example Log (โŒ Fails Governance)
Log.Information("SSN submitted| ssn={ssn}", "123-45-6789");

Triggers:

[CERBI002] Forbidden Field: 'ssn' is not allowed in profile 'default'

๐Ÿงฉ Quick Start (Minimal Working Example)

// Program.cs
using Serilog;
using Cerbi.Serilog.GovernanceAnalyzer;

Log.Logger = new LoggerConfiguration()
    .Filter.WithCerbiGovernance("config/cerbi_governance.json", "default")
    .WriteTo.Console()
    .CreateLogger();

Log.Information("User signed in| userId={UserId}", "abc-123");

.csproj snippet:

<None Include="config\cerbi_governance.json">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

๐Ÿง  IDE Tip: Violations will appear directly in Visual Studio, Rider, or in CI builds using dotnet build. Strict mode causes compile failure.


๐Ÿง  Governance Enforcement Example

(see above config)


๐Ÿ‘ฅ Plugin Support (Advanced)

Create custom enforcement logic with ICustomGovernancePlugin:

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

    public bool Validate(string profileName, Dictionary<string, object> data, out List<string> failures, out int impact)
    {
        failures = new(); impact = 0;
        if (data.TryGetValue("Environment", out var env) &&
            env?.ToString() == "Production" &&
            !data.ContainsKey("TeamId"))
        {
            failures.Add("Missing TeamId in Production logs");
            impact = 5;
            return false;
        }
        return true;
    }
}

๐Ÿ“„ License & Support

Cerbi LLC is not affiliated with or endorsed by Serilog or its maintainers. Serilog is a separate open-source project governed by its own license and maintainers.


โš–๏ธ Secure โ€ข ๐Ÿ“Š Structured โ€ข โœ… Compliant Cerbi Governance Analyzer for Serilog โ€” by Cerbi LLC

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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.2 152 5/26/2025
1.0.0 146 5/8/2025