namespace Nonemm.EngineProbe; /// The probe's report: every line on the screen and in the file, stamped with /// the milliseconds since the probe started. The timing is the point of the /// report, so nothing is written without it. public sealed class ProbeLog : IDisposable { private readonly StreamWriter file; private readonly Lock gate = new(); private readonly long started = Environment.TickCount64; public ProbeLog(string path) { Path = System.IO.Path.GetFullPath(path); file = new StreamWriter(Path, append: false) { AutoFlush = true }; } public string Path { get; } public long Elapsed => Environment.TickCount64 - started; public void Write(string text) { lock (gate) { string line = $"{Elapsed,7} ms {text}"; Console.WriteLine(line); file.WriteLine(line); } } /// A heading, so the file can be read a step at a time. public void Step(string name) { lock (gate) { Console.WriteLine(); Console.WriteLine($"== {name}"); file.WriteLine(); file.WriteLine($"== {name}"); } } public void Dispose() => file.Dispose(); }