refactor(telemetry.serilog): review fixes (thread-safe redactor, bootstrap logger, minlevel ordering, test coverage)

This commit is contained in:
Joseph Doherty
2026-06-01 07:48:57 -04:00
parent 37fb84f477
commit f1240c0bd4
7 changed files with 140 additions and 48 deletions
@@ -43,4 +43,33 @@ public sealed class EnricherTests
Environment.MachineName,
ScalarValue(logEvent, ZbLogEnricherNames.NodeHostname));
}
[Fact]
public void Null_SiteId_and_NodeRole_are_suppressed_but_NodeHostname_is_always_present()
{
var sink = new InMemorySink();
var options = new ZbTelemetryOptions
{
ServiceName = "otopcua",
SiteId = null,
NodeRole = null,
};
var loggerConfig = new LoggerConfiguration();
ZbSerilogConfig.Apply(loggerConfig, options);
using var logger = loggerConfig
.WriteTo.Sink(sink)
.CreateLogger();
logger.Information("hello");
var logEvent = Assert.Single(sink.LogEvents);
Assert.False(logEvent.Properties.ContainsKey(ZbLogEnricherNames.SiteId),
"SiteId should be absent when null");
Assert.False(logEvent.Properties.ContainsKey(ZbLogEnricherNames.NodeRole),
"NodeRole should be absent when null");
Assert.Equal(
Environment.MachineName,
ScalarValue(logEvent, ZbLogEnricherNames.NodeHostname));
}
}