fix(scripting): explicit companion logger + disposable ScriptRootLogger (T2 review)
This commit is contained in:
@@ -11,15 +11,23 @@ namespace ZB.MOM.WW.OtOpcUa.Core.Scripting;
|
||||
/// file sink, the <see cref="ScriptLogCompanionSink"/> mirroring errors to the main log,
|
||||
/// and the <see cref="ScriptLogTopicSink"/> fanning entries onto the cluster
|
||||
/// <c>script-logs</c> topic for the live Script-log Admin UI page.
|
||||
/// <para>
|
||||
/// Implements <see cref="IDisposable"/> so the DI container flushes the rolling-file
|
||||
/// sink on graceful host shutdown.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public sealed class ScriptRootLogger
|
||||
public sealed class ScriptRootLogger : IDisposable
|
||||
{
|
||||
/// <summary>Gets the composed root script logger that evaluators derive per-script loggers from.</summary>
|
||||
public Serilog.ILogger Logger { get; }
|
||||
private readonly Serilog.Core.Logger _logger;
|
||||
|
||||
/// <summary>Initializes a new instance of the <see cref="ScriptRootLogger"/> class.</summary>
|
||||
/// <param name="logger">The composed root script logger. Must not be <c>null</c>.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown when <paramref name="logger"/> is <c>null</c>.</exception>
|
||||
public ScriptRootLogger(Serilog.ILogger logger) =>
|
||||
Logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
/// <summary>The composed root script logger (file + companion mirror + DPS topic sink).</summary>
|
||||
public Serilog.ILogger Logger => _logger;
|
||||
|
||||
/// <summary>Initializes a new <see cref="ScriptRootLogger"/>.</summary>
|
||||
/// <param name="logger">The composed Serilog logger; owned + disposed by this wrapper.</param>
|
||||
public ScriptRootLogger(Serilog.Core.Logger logger) =>
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
|
||||
/// <summary>Disposes the underlying logger, flushing the rolling-file sink.</summary>
|
||||
public void Dispose() => _logger.Dispose();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user