Skip to content

Commit

Permalink
Fixed error when flushing all logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaoticz committed Jan 1, 2025
1 parent 88e0a1c commit 4d7f667
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions NadekoHub/Features/BotConfig/Services/LogWriter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NadekoHub.Features.AppConfig.Models;
using NadekoHub.Features.BotConfig.Models;
using NadekoHub.Features.BotConfig.Services.Abstractions;
using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
using System.Text;

Expand All @@ -11,7 +12,7 @@ namespace NadekoHub.Features.BotConfig.Services;
/// </summary>
public sealed class LogWriter : ILogWriter
{
private readonly Dictionary<Guid, StringBuilder> _botLogs = [];
private readonly ConcurrentDictionary<Guid, StringBuilder> _botLogs = [];
private readonly ReadOnlyAppSettings _appConfig;

/// <inheritdoc/>
Expand All @@ -27,7 +28,11 @@ public LogWriter(ReadOnlyAppSettings appConfig)
/// <inheritdoc/>
public async Task<bool> FlushAllAsync(bool removeFromMemory = false, CancellationToken cToken = default)
{
var result = await Task.WhenAll(_botLogs.Keys.Select(x => FlushAsync(x, removeFromMemory, cToken)));
var result = await Task.WhenAll(_botLogs.Keys.Select(x => FlushAsync(x, false, cToken)));

if (removeFromMemory)
_botLogs.Clear();

return result.Any(x => x);
}

Expand All @@ -38,7 +43,7 @@ public async Task<bool> FlushAsync(Guid botId, bool removeFromMemory = false, Ca
return false;

if (removeFromMemory)
_botLogs.Remove(botId);
_botLogs.Remove(botId, out _);

if (logStringBuilder.Length is 0)
return false;
Expand Down

0 comments on commit 4d7f667

Please sign in to comment.