diff --git a/Directory.Build.props b/Directory.Build.props
index 32a01573..3b2d07f1 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -4,7 +4,7 @@
- 1.0.30
+ 1.0.31
diff --git a/GitHubReleaseNotes.txt b/GitHubReleaseNotes.txt
index a629bdf3..cd35da1a 100644
--- a/GitHubReleaseNotes.txt
+++ b/GitHubReleaseNotes.txt
@@ -1,3 +1,3 @@
https://github.com/StefH/GitHubReleaseNotes
-GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid --version 1.0.30.0
\ No newline at end of file
+GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid --version 1.0.31.0
\ No newline at end of file
diff --git a/src/WireMock.Net/Owin/IWireMockMiddlewareOptions.cs b/src/WireMock.Net/Owin/IWireMockMiddlewareOptions.cs
index 31e10003..882164f0 100644
--- a/src/WireMock.Net/Owin/IWireMockMiddlewareOptions.cs
+++ b/src/WireMock.Net/Owin/IWireMockMiddlewareOptions.cs
@@ -1,9 +1,9 @@
using System;
using System.Collections.Concurrent;
-using System.Collections.ObjectModel;
using WireMock.Handlers;
using WireMock.Logging;
using WireMock.Matchers;
+using WireMock.Util;
#if !USE_ASPNETCORE
using Owin;
#else
@@ -26,7 +26,7 @@ namespace WireMock.Owin
ConcurrentDictionary Scenarios { get; }
- ObservableCollection LogEntries { get; }
+ ConcurrentObservableCollection LogEntries { get; }
int? RequestLogExpirationDuration { get; set; }
diff --git a/src/WireMock.Net/Owin/WireMockMiddleware.cs b/src/WireMock.Net/Owin/WireMockMiddleware.cs
index d2bbec9b..cf7c1b37 100644
--- a/src/WireMock.Net/Owin/WireMockMiddleware.cs
+++ b/src/WireMock.Net/Owin/WireMockMiddleware.cs
@@ -162,7 +162,8 @@ namespace WireMock.Owin
if (_options.MaxRequestLogCount != null)
{
- foreach (var logEntry in _options.LogEntries.OrderBy(le => le.RequestMessage.DateTime).Take(_options.LogEntries.Count - _options.MaxRequestLogCount.Value).ToList())
+ var logEntries = _options.LogEntries.ToList();
+ foreach (var logEntry in logEntries.OrderBy(le => le.RequestMessage.DateTime).Take(logEntries.Count - _options.MaxRequestLogCount.Value))
{
_options.LogEntries.Remove(logEntry);
}
@@ -172,7 +173,7 @@ namespace WireMock.Owin
{
var checkTime = DateTime.UtcNow.AddHours(-_options.RequestLogExpirationDuration.Value);
- foreach (var logEntry in _options.LogEntries.Where(le => le.RequestMessage.DateTime < checkTime).ToList())
+ foreach (var logEntry in _options.LogEntries.ToList().Where(le => le.RequestMessage.DateTime < checkTime))
{
_options.LogEntries.Remove(logEntry);
}
diff --git a/src/WireMock.Net/Owin/WireMockMiddlewareOptions.cs b/src/WireMock.Net/Owin/WireMockMiddlewareOptions.cs
index 81552f54..fa3c3ed6 100644
--- a/src/WireMock.Net/Owin/WireMockMiddlewareOptions.cs
+++ b/src/WireMock.Net/Owin/WireMockMiddlewareOptions.cs
@@ -27,7 +27,7 @@ namespace WireMock.Owin
public ConcurrentDictionary Scenarios { get; } = new ConcurrentDictionary();
- public ObservableCollection LogEntries { get; } = new ConcurrentObservableCollection();
+ public ConcurrentObservableCollection LogEntries { get; } = new ConcurrentObservableCollection();
public int? RequestLogExpirationDuration { get; set; }
diff --git a/src/WireMock.Net/Server/FluentMockServer.LogEntries.cs b/src/WireMock.Net/Server/FluentMockServer.LogEntries.cs
index b9d0b55d..2bfa01e3 100644
--- a/src/WireMock.Net/Server/FluentMockServer.LogEntries.cs
+++ b/src/WireMock.Net/Server/FluentMockServer.LogEntries.cs
@@ -3,11 +3,11 @@ using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
+using System.Linq;
using JetBrains.Annotations;
using WireMock.Logging;
-using WireMock.Matchers.Request;
-using System.Linq;
using WireMock.Matchers;
+using WireMock.Matchers.Request;
namespace WireMock.Server
{
@@ -27,7 +27,7 @@ namespace WireMock.Server
/// Gets the request logs.
///
[PublicAPI]
- public IEnumerable LogEntries => new ReadOnlyCollection(_options.LogEntries.ToArray());
+ public IEnumerable LogEntries => new ReadOnlyCollection(_options.LogEntries.ToList());
///
/// The search log-entries based on matchers.
@@ -73,7 +73,7 @@ namespace WireMock.Server
public bool DeleteLogEntry(Guid guid)
{
// Check a logentry exists with the same GUID, if so, remove it.
- var existing = _options.LogEntries.FirstOrDefault(m => m.Guid == guid);
+ var existing = _options.LogEntries.ToList().FirstOrDefault(m => m.Guid == guid);
if (existing != null)
{
_options.LogEntries.Remove(existing);
diff --git a/src/WireMock.Net/Util/ConcurrentObservableCollection.cs b/src/WireMock.Net/Util/ConcurrentObservableCollection.cs
index f85381ca..09854c50 100644
--- a/src/WireMock.Net/Util/ConcurrentObservableCollection.cs
+++ b/src/WireMock.Net/Util/ConcurrentObservableCollection.cs
@@ -1,14 +1,15 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Linq;
namespace WireMock.Util
{
///
- /// A special Collection that overrides methods of to make them thread safe
+ /// A special Collection that overrides methods of to make them thread safe.
///
/// The type of elements in the collection.
///
- public class ConcurrentObservableCollection : ObservableCollection
+ internal class ConcurrentObservableCollection : ObservableCollection
{
private readonly object _lockObject = new object();
@@ -73,5 +74,13 @@ namespace WireMock.Util
base.MoveItem(oldIndex, newIndex);
}
}
+
+ public List ToList()
+ {
+ lock (_lockObject)
+ {
+ return Items.ToList();
+ }
+ }
}
}
\ No newline at end of file