using Serilog.Core; using Serilog.Events; namespace OF_DL.Gui.Services; public sealed class DownloadErrorLogTracker { private int _sessionActive; private int _errorLoggedInSession; public bool IsSessionActive => Volatile.Read(ref _sessionActive) == 1; public void StartSession() { Interlocked.Exchange(ref _errorLoggedInSession, 0); Interlocked.Exchange(ref _sessionActive, 1); } public bool StopSession() { Interlocked.Exchange(ref _sessionActive, 0); return Volatile.Read(ref _errorLoggedInSession) == 1; } public void RecordError() { if (!IsSessionActive) { return; } Interlocked.Exchange(ref _errorLoggedInSession, 1); } } internal sealed class DownloadErrorTrackingSink(DownloadErrorLogTracker tracker) : ILogEventSink { public void Emit(LogEvent logEvent) { if (logEvent.Level >= LogEventLevel.Error) { tracker.RecordError(); } } }