mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-23 16:58:27 +02:00
Fix unsubscribe from LogEntriesChanged event handler (#872)
* Fix unsubscribe from LogEntriesChanged event handler * . * f
This commit is contained in:
@@ -14,26 +14,12 @@ namespace WireMock.Server;
|
||||
|
||||
public partial class WireMockServer
|
||||
{
|
||||
/// <inheritdoc cref="IWireMockServer.LogEntriesChanged" />
|
||||
/// <inheritdoc />
|
||||
[PublicAPI]
|
||||
public event NotifyCollectionChangedEventHandler LogEntriesChanged
|
||||
{
|
||||
add
|
||||
{
|
||||
_options.LogEntries.CollectionChanged += (sender, eventRecordArgs) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
value(sender, eventRecordArgs);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
_options.Logger.Error("Error calling the LogEntriesChanged event handler: {0}", exception.Message);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
remove => _options.LogEntries.CollectionChanged -= value;
|
||||
add => _logEntriesChanged += value;
|
||||
remove => _logEntriesChanged -= value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IWireMockServer.LogEntries" />
|
||||
@@ -90,4 +76,24 @@ public partial class WireMockServer
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private NotifyCollectionChangedEventHandler? _logEntriesChanged;
|
||||
|
||||
private void LogEntries_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
if (_logEntriesChanged is { })
|
||||
{
|
||||
foreach (var handler in _logEntriesChanged.GetInvocationList())
|
||||
{
|
||||
try
|
||||
{
|
||||
handler.DynamicInvoke(this, e);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
_options.Logger.Error("Error calling the LogEntriesChanged event handler: {0}", exception.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user