Files
ScadaBridge/src/ZB.MOM.WW.ScadaBridge.DelmiaNotifier/DiagLog.cs
T
Joseph Doherty 5a878b78d4 docs(xml): fill missing XML doc comments + strip task-tracking refs across src (fixdocs)
Add missing <summary>/<param>/<returns>/<typeparam> tags and switch
interface implementations to <inheritdoc/> across 106 files; strip
project bookkeeping identifiers (Task NN, #05-TNN, PLAN-04, StoreAndForward-0NN)
from shipped code comments while preserving the descriptive rationale.
Comment-only: zero code-logic lines changed; solution builds 0/0.

Claude-Session: https://claude.ai/code/session_01MtdgwpEeCUn6cUA5f1LMPj
2026-07-10 08:23:56 -04:00

42 lines
1.4 KiB
C#

using System.Globalization;
namespace ZB.MOM.WW.ScadaBridge.DelmiaNotifier;
/// <summary>
/// Best-effort diagnostics: writes UTC-timestamped lines to stderr and, when a log path is configured,
/// appends them to a file (relative to the exe). Never throws — diagnostics must not break the YES/NO path.
/// </summary>
internal sealed class DiagLog(string? logPath)
{
private readonly string? _logPath = string.IsNullOrWhiteSpace(logPath) ? null : logPath;
/// <summary>Writes a UTC-timestamped diagnostic line to stderr and, if configured, the log file.</summary>
/// <param name="message">The message text to log.</param>
public void Write(string message)
{
var line = string.Create(CultureInfo.InvariantCulture, $"{DateTime.UtcNow:yyyy-MM-ddTHH:mm:ss.fffZ} {message}");
Console.Error.WriteLine(line);
if (_logPath is null)
{
return;
}
try
{
var fullPath = Path.IsPathRooted(_logPath) ? _logPath : Path.Combine(AppContext.BaseDirectory, _logPath);
var dir = Path.GetDirectoryName(fullPath);
if (!string.IsNullOrEmpty(dir))
{
Directory.CreateDirectory(dir);
}
File.AppendAllText(fullPath, line + Environment.NewLine);
}
catch
{
// diagnostics are best-effort; swallow file errors so the YES/NO contract is unaffected
}
}
}