using System.IO; namespace TeamsISO.App; /// /// Bare-metal startup tracer that opens, appends, and closes a file on /// every call. Used to capture what's happening BEFORE Serilog comes up /// (and to capture failures that would prevent Serilog from coming up at /// all). Failures here are swallowed — we never want diagnostics to crash /// the very thing we're trying to diagnose. /// /// File lives at %LOCALAPPDATA%\TeamsISO\startup-trace.log. Grows /// without rotation; expected to be tiny since each launch writes ~20 /// lines. Acceptable cost for catching launch-time regressions. /// internal static class StartupTrace { private static readonly object _gate = new(); public static void Write(string message) { try { var dir = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "TeamsISO"); Directory.CreateDirectory(dir); var path = Path.Combine(dir, "startup-trace.log"); var line = $"[{DateTimeOffset.Now:yyyy-MM-dd HH:mm:ss.fff}] [PID {Environment.ProcessId}] {message}{Environment.NewLine}"; lock (_gate) { File.AppendAllText(path, line); } } catch { // Diagnostics must NEVER crash startup. } } }