feat(scripting): evaluators log through root script logger → script-log page (F8)

This commit is contained in:
Joseph Doherty
2026-06-10 12:03:51 -04:00
parent bf86b3def6
commit bd2dd05a0c
7 changed files with 245 additions and 36 deletions
@@ -61,4 +61,34 @@ public sealed class ScriptLoggerFactory
throw new ArgumentException("Script name is required.", nameof(scriptName));
return _rootLogger.ForContext(ScriptNameProperty, scriptName);
}
/// <summary>
/// Create a per-evaluation script logger bound with the supplied identity properties.
/// <see cref="ScriptIdProperty"/> is always bound; <see cref="VirtualTagIdProperty"/>,
/// <see cref="AlarmIdProperty"/>, and <see cref="EquipmentIdProperty"/> are bound only
/// when the corresponding argument is non-null. Every event the returned logger emits
/// carries these properties so the <see cref="ScriptLogTopicSink"/> can attribute each
/// line on the Script-log page.
/// </summary>
/// <param name="scriptId">The Script row identifier; always bound. Required.</param>
/// <param name="virtualTagId">VirtualTag context, when the script runs against a virtual tag.</param>
/// <param name="alarmId">ScriptedAlarm context, when the script runs an alarm predicate.</param>
/// <param name="equipmentId">Equipment scope, for per-equipment script evaluations.</param>
/// <returns>An ILogger instance bound with the supplied identity properties.</returns>
/// <exception cref="ArgumentException">Thrown when <paramref name="scriptId"/> is null or whitespace.</exception>
public ILogger Create(
string scriptId,
string? virtualTagId = null,
string? alarmId = null,
string? equipmentId = null)
{
if (string.IsNullOrWhiteSpace(scriptId))
throw new ArgumentException("Script id is required.", nameof(scriptId));
var logger = _rootLogger.ForContext(ScriptIdProperty, scriptId);
if (virtualTagId is not null) logger = logger.ForContext(VirtualTagIdProperty, virtualTagId);
if (alarmId is not null) logger = logger.ForContext(AlarmIdProperty, alarmId);
if (equipmentId is not null) logger = logger.ForContext(EquipmentIdProperty, equipmentId);
return logger;
}
}