From 2e33bcc464ffc6f0aa4a2d48358b9dce44dc675e Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Fri, 23 Aug 2019 11:38:29 +0000 Subject: [PATCH] #327 (#328) --- src/WireMock.Net/Owin/WireMockMiddleware.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/WireMock.Net/Owin/WireMockMiddleware.cs b/src/WireMock.Net/Owin/WireMockMiddleware.cs index 2e9cd3d0..d2bbec9b 100644 --- a/src/WireMock.Net/Owin/WireMockMiddleware.cs +++ b/src/WireMock.Net/Owin/WireMockMiddleware.cs @@ -162,10 +162,9 @@ namespace WireMock.Owin if (_options.MaxRequestLogCount != null) { - var amount = _options.LogEntries.Count - _options.MaxRequestLogCount.Value; - for (int i = 0; i < amount; i++) + foreach (var logEntry in _options.LogEntries.OrderBy(le => le.RequestMessage.DateTime).Take(_options.LogEntries.Count - _options.MaxRequestLogCount.Value).ToList()) { - _options.LogEntries.RemoveAt(0); + _options.LogEntries.Remove(logEntry); } } @@ -173,13 +172,9 @@ namespace WireMock.Owin { var checkTime = DateTime.UtcNow.AddHours(-_options.RequestLogExpirationDuration.Value); - for (var i = _options.LogEntries.Count - 1; i >= 0; i--) + foreach (var logEntry in _options.LogEntries.Where(le => le.RequestMessage.DateTime < checkTime).ToList()) { - var le = _options.LogEntries[i]; - if (le.RequestMessage.DateTime <= checkTime) - { - _options.LogEntries.RemoveAt(i); - } + _options.LogEntries.Remove(logEntry); } } }