From 89b23258aaf7eb7c6d6bb61097ffb0364b82d5f1 Mon Sep 17 00:00:00 2001 From: Harrison Deng Date: Thu, 8 Apr 2021 22:26:27 -0500 Subject: [PATCH] Logger is now thread safe. --- src/GameServiceWarden.Core/Logging/Logger.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/GameServiceWarden.Core/Logging/Logger.cs b/src/GameServiceWarden.Core/Logging/Logger.cs index c84a9e4..6dc23b1 100644 --- a/src/GameServiceWarden.Core/Logging/Logger.cs +++ b/src/GameServiceWarden.Core/Logging/Logger.cs @@ -1,10 +1,11 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; namespace GameServiceWarden.Core.Logging { public static class Logger { - private static readonly Dictionary listeners = new Dictionary(); + private static readonly ConcurrentDictionary listeners = new ConcurrentDictionary(); /// /// Logs the message to listeners that are listening to the set severity of the message or greater. @@ -33,7 +34,8 @@ namespace GameServiceWarden.Core.Logging /// /// The listener to remove. public static void RemoveLogListener(ILogReceiver listener) { - listeners.Remove(listener.Identifier); + ILogReceiver receiver; + listeners.TryRemove(listener.Identifier, out receiver); } ///