diff --git a/src/IO.Ably.Tests.Shared/Helpers/DefaultLogger.cs b/src/IO.Ably.Tests.Shared/Helpers/DefaultLogger.cs index 5edf2c6c0..dd68deda8 100644 --- a/src/IO.Ably.Tests.Shared/Helpers/DefaultLogger.cs +++ b/src/IO.Ably.Tests.Shared/Helpers/DefaultLogger.cs @@ -5,7 +5,26 @@ namespace IO.Ably.Tests.Shared.Helpers /// An utility class for logging various messages. public static class DefaultLogger { - internal static ILogger LoggerInstance => InternalLogger.Create(); + private static readonly object SyncLock = new object(); + private static ILogger _loggerInstance; + + internal static ILogger LoggerInstance + { + get + { + if (_loggerInstance == null) + { + lock (SyncLock) + { + _loggerInstance = InternalLogger.Create(); + } + } + + return _loggerInstance; + } + + set => _loggerInstance = value; + } /// Maximum level to log. /// E.g. set to LogLevel.Warning to have only errors and warnings in the log. diff --git a/src/IO.Ably.Tests.Shared/Realtime/DeltaSandboxSpecs.cs b/src/IO.Ably.Tests.Shared/Realtime/DeltaSandboxSpecs.cs index b3d13cb70..e18abb32b 100644 --- a/src/IO.Ably.Tests.Shared/Realtime/DeltaSandboxSpecs.cs +++ b/src/IO.Ably.Tests.Shared/Realtime/DeltaSandboxSpecs.cs @@ -231,7 +231,7 @@ public async Task WhenDeltaDecodeFail_ShouldSetStateToAttachingLogTheErrorAndDis var firstMessageReceived = new TaskCompletionAwaiter(); using (((IInternalLogger)Logger).CreateDisposableLoggingContext(testSink)) { - var realtime = await GetRealtimeClient(protocol); + var realtime = await GetRealtimeClient(protocol, (options, _) => options.LogHandler = testSink); var channel = realtime.Channels.Get(channelName, new ChannelOptions(channelParams: new ChannelParams { { "delta", "vcdiff" } })); var received = new List();