mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2026-05-07 13:55:47 +00:00
Flush the error log before exit (ryubing/ryujinx!163)
See merge request ryubing/ryujinx!163
This commit is contained in:
@@ -27,6 +27,17 @@ namespace Ryujinx.Common.Logging.Targets
|
||||
|
||||
private readonly int _overflowTimeout;
|
||||
|
||||
private sealed class FlushEventArgs : LogEventArgs
|
||||
{
|
||||
public readonly ManualResetEventSlim SignalEvent;
|
||||
|
||||
public FlushEventArgs(ManualResetEventSlim signalEvent)
|
||||
: base(LogLevel.Notice, TimeSpan.Zero, string.Empty, string.Empty)
|
||||
{
|
||||
SignalEvent = signalEvent;
|
||||
}
|
||||
}
|
||||
|
||||
string ILogTarget.Name => _target.Name;
|
||||
|
||||
public AsyncLogTargetWrapper(ILogTarget target, int queueLimit = -1, AsyncLogTargetOverflowAction overflowAction = AsyncLogTargetOverflowAction.Block)
|
||||
@@ -41,7 +52,15 @@ namespace Ryujinx.Common.Logging.Targets
|
||||
{
|
||||
try
|
||||
{
|
||||
_target.Log(this, _messageQueue.Take());
|
||||
LogEventArgs item = _messageQueue.Take();
|
||||
|
||||
if (item is FlushEventArgs flush)
|
||||
{
|
||||
flush.SignalEvent.Set();
|
||||
continue;
|
||||
}
|
||||
|
||||
_target.Log(this, item);
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
@@ -68,6 +87,26 @@ namespace Ryujinx.Common.Logging.Targets
|
||||
}
|
||||
}
|
||||
|
||||
public void Flush()
|
||||
{
|
||||
if (_messageQueue.Count == 0 || _messageQueue.IsAddingCompleted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using var signal = new ManualResetEventSlim(false);
|
||||
try
|
||||
{
|
||||
_messageQueue.Add(new FlushEventArgs(signal));
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
signal.Wait();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
Reference in New Issue
Block a user