/// <summary> /// Dumps all events to an outputAdapter instance if one is available /// </summary> /// <param name="state"></param> private void DumpEvents(object?state) { try { using (var lk = globalLogCfg.PauseLogging()) { lk.Exclusive(() => { using (var scope = services.CreateScope()) { var adapter = scope.ServiceProvider.GetService <ILogOutputAdapter>(); if (adapter != null) { EnableDebugMessages = globalLogCfg.EnableDebugMessages; if (EnableDebugMessages) { LogEnvironment.EnableDebugMessages(); } else { LogEnvironment.DisableDebugMessages(); } if (!events.IsEmpty) { try { while (events.TryDequeue(out var eventData)) { try { adapter.PopulateEvent(eventData); } catch (Exception ex) { System.Console.WriteLine(ex.OutlineException()); } } } finally { adapter.Flush(); } } } else { events.Clear(); } } }); } } catch (Exception ex) { System.Console.WriteLine(ex.OutlineException()); events.Clear(); } finally { if (!disposed) { timer.Change(10000, Timeout.Infinite); } } }