feat(host): build the process logger through the shared AddZbSerilog bootstrap (#94)
Switch ScadaBridge from its own LoggerConfigurationFactory to AddZbSerilog (ZB.MOM.WW.Telemetry(.Serilog) 0.1.0 -> 0.2.0) using the two 0.2.0 hooks: - MinimumLevelGovernor: ScadaBridge:Logging:MinimumLevel, applied after ReadFrom.Configuration so it outranks Serilog:MinimumLevel (never null, so the floor never defers to the Serilog key; Override:* namespace entries still apply; the one-shot conflict / unparseable-value warnings are unchanged). - ConfigureLogger: the standby active-node exclusion filter (register row 71), the configured node identity (the shared bootstrap stamps NodeHostname from the machine name and skips empty values; an overwriting enricher keeps the configured ScadaBridge:Node values verbatim), Enrich.FromLogContext and the ExecutionLogCaptureSink. ScadaBridgeLogging runs AddZbSerilog on a small pre-host builder and Program installs the result as the static Log.Logger; both web hosts keep UseSerilog() over it. One logger and one file-sink handle per process, usable before the host is built (startup banner, warnings, pre-host Fatal), by SerilogAkkaLogger, and after the host is disposed (shutdown line, unexpected-termination Fatal) — AddZbSerilog's own DI registration would leave Log.Logger alone and have the host dispose the logger. LoggerConfigurationFactory is deleted (nothing else used it). Tests: existing logging/standby/sink tests now run through the new pipeline, plus ScadaBridgeLoggingParityTests (level precedence, Override:* still applies, one-shot warning, configured identity incl. NodeHostname != MachineName and empty SiteId, exact property set of a plain line, trace_id/span_id). Mutation-checked: governor deferring, filter removed, identity enricher removed, FromLogContext removed, capture sink removed each fail tests. Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
@@ -23,10 +23,8 @@ public class LoggerConfigurationTests
|
||||
public void MinimumLevel_Warning_SuppressesInformationLogs()
|
||||
{
|
||||
var sink = new InMemorySink();
|
||||
var logger = LoggerConfigurationFactory
|
||||
.Build(BuildConfig("Warning"), "Central", "central", "node1")
|
||||
.WriteTo.Sink(sink)
|
||||
.CreateLogger();
|
||||
var logger = ScadaBridgeLogging.CreateLogger(
|
||||
BuildConfig("Warning"), "Central", "central", "node1", new StringWriter(), lc => lc.WriteTo.Sink(sink));
|
||||
|
||||
logger.Information("info message");
|
||||
logger.Warning("warning message");
|
||||
@@ -40,10 +38,8 @@ public class LoggerConfigurationTests
|
||||
public void LogContextProperties_AreEnrichedOntoEvents()
|
||||
{
|
||||
var sink = new InMemorySink();
|
||||
var logger = LoggerConfigurationFactory
|
||||
.Build(BuildConfig(null), "Site", "site-a", "node1")
|
||||
.WriteTo.Sink(sink)
|
||||
.CreateLogger();
|
||||
var logger = ScadaBridgeLogging.CreateLogger(
|
||||
BuildConfig(null), "Site", "site-a", "node1", new StringWriter(), lc => lc.WriteTo.Sink(sink));
|
||||
|
||||
var id = Guid.NewGuid();
|
||||
using (Serilog.Context.LogContext.PushProperty("ExecutionId", id))
|
||||
@@ -62,10 +58,8 @@ public class LoggerConfigurationTests
|
||||
public void MinimumLevel_Debug_AllowsDebugLogs()
|
||||
{
|
||||
var sink = new InMemorySink();
|
||||
var logger = LoggerConfigurationFactory
|
||||
.Build(BuildConfig("Debug"), "Site", "site-a", "node1")
|
||||
.WriteTo.Sink(sink)
|
||||
.CreateLogger();
|
||||
var logger = ScadaBridgeLogging.CreateLogger(
|
||||
BuildConfig("Debug"), "Site", "site-a", "node1", new StringWriter(), lc => lc.WriteTo.Sink(sink));
|
||||
|
||||
logger.Debug("debug message");
|
||||
|
||||
@@ -78,10 +72,8 @@ public class LoggerConfigurationTests
|
||||
public void MinimumLevel_Absent_DefaultsToInformation()
|
||||
{
|
||||
var sink = new InMemorySink();
|
||||
var logger = LoggerConfigurationFactory
|
||||
.Build(BuildConfig(null), "Central", "central", "node1")
|
||||
.WriteTo.Sink(sink)
|
||||
.CreateLogger();
|
||||
var logger = ScadaBridgeLogging.CreateLogger(
|
||||
BuildConfig(null), "Central", "central", "node1", new StringWriter(), lc => lc.WriteTo.Sink(sink));
|
||||
|
||||
logger.Debug("debug message");
|
||||
logger.Information("info message");
|
||||
@@ -101,7 +93,7 @@ public class LoggerConfigurationTests
|
||||
{
|
||||
var writer = new StringWriter();
|
||||
|
||||
var result = LoggerConfigurationFactory.ParseLevel("Informaiton", writer);
|
||||
var result = ScadaBridgeLogging.ParseLevel("Informaiton", writer);
|
||||
|
||||
Assert.Equal(LogEventLevel.Information, result);
|
||||
var warning = writer.ToString();
|
||||
@@ -116,8 +108,8 @@ public class LoggerConfigurationTests
|
||||
{
|
||||
var writer = new StringWriter();
|
||||
|
||||
var nullResult = LoggerConfigurationFactory.ParseLevel(null, writer);
|
||||
var blankResult = LoggerConfigurationFactory.ParseLevel(" ", writer);
|
||||
var nullResult = ScadaBridgeLogging.ParseLevel(null, writer);
|
||||
var blankResult = ScadaBridgeLogging.ParseLevel(" ", writer);
|
||||
|
||||
Assert.Equal(LogEventLevel.Information, nullResult);
|
||||
Assert.Equal(LogEventLevel.Information, blankResult);
|
||||
@@ -130,7 +122,7 @@ public class LoggerConfigurationTests
|
||||
{
|
||||
var writer = new StringWriter();
|
||||
|
||||
var result = LoggerConfigurationFactory.ParseLevel("Warning", writer);
|
||||
var result = ScadaBridgeLogging.ParseLevel("Warning", writer);
|
||||
|
||||
Assert.Equal(LogEventLevel.Warning, result);
|
||||
Assert.Empty(writer.ToString());
|
||||
@@ -141,7 +133,7 @@ public class LoggerConfigurationTests
|
||||
/// of truth for the Serilog floor, and the explicit <c>MinimumLevel.Is</c>
|
||||
/// call deliberately runs after <c>ReadFrom.Configuration(...)</c> so a
|
||||
/// <c>Serilog:MinimumLevel</c> entry is overridden. To make that precedence
|
||||
/// visible — instead of silently swallowed — <see cref="LoggerConfigurationFactory.Build(IConfiguration,string,string,string,TextWriter)"/>
|
||||
/// visible — instead of silently swallowed — <see cref="ScadaBridgeLogging.GovernMinimumLevel(IConfiguration,TextWriter)"/>
|
||||
/// writes a one-shot warning when both keys are present. The warning must
|
||||
/// name both values and point the operator at the documented key. When the
|
||||
/// Serilog key is absent the warning is silent.
|
||||
@@ -158,7 +150,7 @@ public class LoggerConfigurationTests
|
||||
})
|
||||
.Build();
|
||||
|
||||
LoggerConfigurationFactory.Build(configuration, "Central", "central", "node1", writer);
|
||||
using var _ = ScadaBridgeLogging.CreateLogger(configuration, "Central", "central", "node1", writer, null);
|
||||
|
||||
var warning = writer.ToString();
|
||||
Assert.Contains("warning", warning, StringComparison.OrdinalIgnoreCase);
|
||||
@@ -180,7 +172,7 @@ public class LoggerConfigurationTests
|
||||
})
|
||||
.Build();
|
||||
|
||||
LoggerConfigurationFactory.Build(configuration, "Central", "central", "node1", writer);
|
||||
using var _ = ScadaBridgeLogging.CreateLogger(configuration, "Central", "central", "node1", writer, null);
|
||||
|
||||
// No Serilog override -> no override-warning. (The ScadaBridge value is
|
||||
// a recognised level, so ParseLevel is silent too.)
|
||||
@@ -201,8 +193,7 @@ public class LoggerConfigurationTests
|
||||
public void Build_IncludesTheExecutionCaptureSink()
|
||||
{
|
||||
var configuration = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string?>()).Build();
|
||||
using var logger = LoggerConfigurationFactory.Build(configuration, "Site", "site-a", "node1", new StringWriter())
|
||||
.CreateLogger();
|
||||
using var logger = ScadaBridgeLogging.CreateLogger(configuration, "Site", "site-a", "node1", new StringWriter(), null);
|
||||
var id = Guid.NewGuid();
|
||||
var target = new CollectingTarget();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user