feat(logging): stamp ExecutionId/InstanceName/ScriptName on the Serilog LogContext per run (ScadaBridge#56)
The site script and alarm on-trigger launchers push the run identity onto LogContext for the run's lifetime and the host now enables Enrich.FromLogContext(), so log lines written on the run's own async call chain carry the id. Bounded part only: LogContext does not cross an Akka message hop, so Instance Actor/DCL/S&F lines and a site_events execution-id column remain open (documented in the step-logs design doc section 9). Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -35,6 +35,28 @@ public class LoggerConfigurationTests
|
||||
Assert.Equal(LogEventLevel.Warning, sink.LogEvents[0].Level);
|
||||
}
|
||||
|
||||
/// <summary>Verifies the logger enriches events from the Serilog LogContext, so a run's pushed ExecutionId reaches the sink (ScadaBridge#56).</summary>
|
||||
[Fact]
|
||||
public void LogContextProperties_AreEnrichedOntoEvents()
|
||||
{
|
||||
var sink = new InMemorySink();
|
||||
var logger = LoggerConfigurationFactory
|
||||
.Build(BuildConfig(null), "Site", "site-a", "node1")
|
||||
.WriteTo.Sink(sink)
|
||||
.CreateLogger();
|
||||
|
||||
var id = Guid.NewGuid();
|
||||
using (Serilog.Context.LogContext.PushProperty("ExecutionId", id))
|
||||
{
|
||||
logger.Information("inside");
|
||||
}
|
||||
logger.Information("outside");
|
||||
|
||||
Assert.Equal(2, sink.LogEvents.Count);
|
||||
Assert.Equal(id.ToString(), sink.LogEvents[0].Properties["ExecutionId"].ToString().Trim('"'));
|
||||
Assert.False(sink.LogEvents[1].Properties.ContainsKey("ExecutionId"));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a Debug minimum level allows Debug logs.</summary>
|
||||
[Fact]
|
||||
public void MinimumLevel_Debug_AllowsDebugLogs()
|
||||
|
||||
Reference in New Issue
Block a user