using System; using System.Collections.Generic; /// /// 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. /// internal static class Diag { internal static readonly bool Verbose = ReadFlag("RADICADE_DIAG"); private static readonly object Gate = new object(); private static readonly HashSet Seen = new HashSet(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; } } /// Per-request tracing: printed only with RADICADE_DIAG=1. 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 { } } /// True the first time this key is seen in the session. internal static bool FirstTime(string key) { try { lock (Gate) return Seen.Add(key); } catch { return false; } } }