namespace Mbproxy.Diagnostics;
///
/// The platform diagnostic sink to wire for Error+ events — picked once,
/// at the composition root, by .
///
internal enum DiagnosticSink
{
///
/// No platform diagnostic sink — console (and rolling-file) sinks only. Used
/// for interactive / dev runs on every OS.
///
None,
///
/// Windows Application Event Log, via . Selected
/// only when the process is hosted as a Windows Service.
///
EventLog,
///
/// Local syslog, via . Selected only when the
/// process is hosted as a systemd service on Linux.
///
Syslog,
}
///
/// Pure platform-selection logic for the Error+ diagnostic sink. Holds no
/// I/O and no host APIs so it is unit-testable for every OS / host combination;
/// the host detection itself happens in .
///
internal static class DiagnosticSinkSelector
{
///
/// Picks the diagnostic sink for the current host:
///
/// - Windows hosted as a Windows Service → .
/// - Linux hosted as a systemd service → .
/// - Everything else — interactive / dev runs, macOS, launches not owned
/// by an init system → .
///
/// The managed-service gate mirrors the original
/// contract: a diagnostic sink is wired only when an init system actually owns
/// the process, so dev / console runs never need an Event Log source registered
/// or a syslog socket reachable.
///
/// Running on Windows.
/// Hosted by the Windows Service Control Manager.
/// Hosted by systemd.
public static DiagnosticSink Select(bool isWindows, bool isWindowsService, bool isSystemd)
{
// Windows takes precedence: isSystemd is meaningless there, and on
// non-Windows isWindowsService is always false.
if (isWindows)
return isWindowsService ? DiagnosticSink.EventLog : DiagnosticSink.None;
return isSystemd ? DiagnosticSink.Syslog : DiagnosticSink.None;
}
}