Files
2026-10-16 23:33:13 -07:00

68 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
/// <summary>
/// Single switch for the per-request chatter the patch used to print on every
/// login (the [Net], [Connection], [Auth], [HttpStatus] and per-connection [TLS]
/// lines). It is OFF by default: the log now carries patch status and real
/// problems only. Set RADICADE_DIAG=1 to get the full trace back when something
/// needs diagnosing.
/// </summary>
internal static class Diag
{
internal static readonly bool Verbose = ReadFlag("RADICADE_DIAG");
private static readonly object Gate = new object();
private static readonly HashSet<string> Seen = new HashSet<string>(StringComparer.Ordinal);
internal static bool ReadFlag(string name)
{
try
{
var raw = Environment.GetEnvironmentVariable(name);
if (string.IsNullOrWhiteSpace(raw)) return false;
var value = raw.Trim().ToLowerInvariant();
return !(value == "0" || value == "off" || value == "false" || value == "no");
}
catch
{
return false;
}
}
/// <summary>Per-request tracing: printed only with RADICADE_DIAG=1.</summary>
internal static void Trace(string message)
{
if (!Verbose) return;
Info(message);
}
internal static void Info(string message)
{
try { RadicadeEacBypassPlugin.LogSource.LogInfo(message); } catch { }
}
internal static void Warn(string message)
{
try { RadicadeEacBypassPlugin.LogSource.LogWarning(message); } catch { }
}
internal static void Error(string message)
{
try { RadicadeEacBypassPlugin.LogSource.LogError(message); } catch { }
}
/// <summary>True the first time this key is seen in the session.</summary>
internal static bool FirstTime(string key)
{
try
{
lock (Gate) return Seen.Add(key);
}
catch
{
return false;
}
}
}