feat(telemetry): AddZbSerilog minimum-level governance hook; bump to 0.2.0 (scadaproj#12)

Adds an additive AddZbSerilog(builder, configure, configureSerilog) overload
taking ZbSerilogOptions:
- MinimumLevelGovernor: Func<IConfiguration, LogEventLevel?> applied with
  MinimumLevel.Is AFTER ReadFrom.Configuration, so an app-owned key (e.g.
  ScadaBridge:Logging:MinimumLevel) outranks Serilog:MinimumLevel; null defers
  to config; Serilog:MinimumLevel:Override:* entries still apply.
- ConfigureLogger: runs last, for app filters/enrichers/sinks (ScadaBridge's
  standby active-node exclusion).

The two-argument overload is unchanged. 8 new tests (4 fail with the hook
neutralized). Telemetry + Telemetry.Serilog 0.1.0 -> 0.2.0, not published.

Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
Joseph Doherty
2026-11-09 13:39:06 -05:00
parent a05ce8c86d
commit 1ab5ca026b
7 changed files with 288 additions and 12 deletions
+21 -4
View File
@@ -112,6 +112,23 @@ builder.AddZbSerilog(o =>
});
```
```csharp
// 0.2.0+: optional hooks for apps whose OWN key governs the minimum level (e.g. ScadaBridge's
// ScadaBridge:Logging:MinimumLevel, which must outrank Serilog:MinimumLevel). The governor runs
// AFTER ReadFrom.Configuration, so a non-null result overrides Serilog:MinimumLevel[:Default];
// null defers to config. Serilog:MinimumLevel:Override:* namespace entries still apply.
// ConfigureLogger runs last (filters, extra enrichers/sinks). Both default to null, in which
// case this is identical to the two-argument overload.
builder.AddZbSerilog(
o => { o.ServiceName = "scadabridge"; o.SiteId = siteId; o.NodeRole = nodeRole; },
s =>
{
s.MinimumLevelGovernor = cfg =>
Enum.TryParse<LogEventLevel>(cfg["ScadaBridge:Logging:MinimumLevel"], true, out var l) ? l : null;
s.ConfigureLogger = (lc, sp) => lc.Filter.ByExcluding(MyFilter);
});
```
---
## Building and testing
@@ -128,8 +145,8 @@ backend):
| Assembly | Tests |
|---|---|
| `ZB.MOM.WW.Telemetry.Tests` | 12 |
| `ZB.MOM.WW.Telemetry.Serilog.Tests` | 17 |
| **Total** | **29** |
| `ZB.MOM.WW.Telemetry.Serilog.Tests` | 30 |
| **Total** | **42** |
---
@@ -142,8 +159,8 @@ dotnet pack ZB.MOM.WW.Telemetry.slnx -c Release -o ./artifacts
Produces two `.nupkg` files in `artifacts/`:
```
ZB.MOM.WW.Telemetry.0.1.0.nupkg
ZB.MOM.WW.Telemetry.Serilog.0.1.0.nupkg
ZB.MOM.WW.Telemetry.0.2.0.nupkg
ZB.MOM.WW.Telemetry.Serilog.0.2.0.nupkg
```
`GeneratePackageOnBuild` is off — pack explicitly as above. Both packages are versioned