Skip to content

Commit d497d00

Browse files
Refactors RequestLogs property to use ConcurrentBag for improved thread safety (#1333)
1 parent 39a7fd7 commit d497d00

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

DevProxy/Logging/RequestLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
2424
{
2525
if (_proxyState.IsRecording)
2626
{
27-
_proxyState.RequestLogs.Add(requestLog);
27+
_proxyState.RequestLogs.Enqueue(requestLog);
2828
}
2929

3030
var requestLogArgs = new RequestLogArgs(requestLog);

DevProxy/Proxy/IProxyState.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using DevProxy.Abstractions.Proxy;
6-
using System.Collections.ObjectModel;
6+
using System.Collections.Concurrent;
77

88
namespace DevProxy.Proxy;
99

@@ -13,5 +13,5 @@ public interface IProxyState
1313
{
1414
Dictionary<string, object> GlobalData { get; }
1515
bool IsRecording { get; set; }
16-
Collection<RequestLog> RequestLogs { get; }
16+
ConcurrentQueue<RequestLog> RequestLogs { get; }
1717
}

DevProxy/Proxy/ProxyState.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
using DevProxy.Abstractions.Proxy;
66
using DevProxy.Abstractions.Utils;
7-
using System.Collections.ObjectModel;
7+
using System.Collections.Concurrent;
88

99
namespace DevProxy.Proxy;
1010

1111
sealed class ProxyState : IProxyState
1212
{
1313
public bool IsRecording { get; set; }
14-
public Collection<RequestLog> RequestLogs { get; set; } = [];
14+
public ConcurrentQueue<RequestLog> RequestLogs { get; set; } = [];
1515
public Dictionary<string, object> GlobalData { get; set; } = new() {
1616
{ ProxyUtils.ReportsKey, new Dictionary<string, object>() }
1717
};

0 commit comments

Comments
 (0)