feat(scripting): root script logger + DPS publisher wired in Host

This commit is contained in:
Joseph Doherty
2026-06-10 11:50:50 -04:00
parent 14fe88fc80
commit 73014258ef
8 changed files with 326 additions and 0 deletions
@@ -0,0 +1,38 @@
using Serilog;
using Serilog.Events;
using ZB.MOM.WW.OtOpcUa.Core.Scripting;
namespace ZB.MOM.WW.OtOpcUa.Host.Logging;
/// <summary>
/// Composes the root script <see cref="Serilog.ILogger"/> — the single pipeline every
/// per-script logger derives from. Fans each script log event out to three destinations:
/// a dedicated rolling <c>scripts-*.log</c> file, the main server log (via
/// <see cref="ScriptLogCompanionSink"/>, mirroring Error-or-higher events at Warning), and
/// the cluster <c>script-logs</c> DPS topic (via <see cref="ScriptLogTopicSink"/>) so the
/// live Script-log Admin UI page can tail script output.
/// </summary>
public static class ScriptRootLoggerFactory
{
/// <summary>
/// Builds the composed root script logger.
/// </summary>
/// <param name="publisher">
/// The publisher the topic sink forwards entries to (the DPS publisher in production).
/// </param>
/// <param name="filePath">
/// Path template for the rolling <c>scripts-*.log</c> file sink (e.g. <c>logs/scripts-.log</c>).
/// </param>
/// <param name="topicMinLevel">
/// Minimum level for events forwarded to the <c>script-logs</c> topic; lower-level events
/// still land in the file sink but are not pushed onto the cluster bus.
/// </param>
/// <returns>The composed root script logger.</returns>
public static Serilog.ILogger Build(IScriptLogPublisher publisher, string filePath, LogEventLevel topicMinLevel)
=> new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.File(filePath, rollingInterval: RollingInterval.Day)
.WriteTo.Sink(new ScriptLogCompanionSink(Serilog.Log.Logger))
.WriteTo.Sink(new ScriptLogTopicSink(publisher, topicMinLevel))
.CreateLogger();
}