Skip to content

Commit 2ac3e2f

Browse files
committed
add IDisposable to UdpSink for proper socket cleanup
1 parent 9a92cb5 commit 2ac3e2f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/Serilog.Sinks.UDP/Sinks/Splunk/UdpSink.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace Serilog.Sinks.Splunk
2727
/// <summary>
2828
/// A sink that logs to Splunk over UDP
2929
/// </summary>
30-
public class UdpSink : IBatchedLogEventSink
30+
public class UdpSink : IBatchedLogEventSink, IDisposable
3131
{
3232
private readonly SplunkUdpSinkConnectionInfo _connectionInfo;
3333
private readonly ITextFormatter _formatter;
@@ -77,9 +77,19 @@ private void Connect()
7777
/// Releases resources used by the sink.
7878
/// </summary>
7979
/// <param name="disposing">True if called from Dispose, false if called from a finalizer.</param>
80-
protected void Dispose(bool disposing)
80+
protected virtual void Dispose(bool disposing)
8181
{
82-
DisposeSocket();
82+
if (disposing)
83+
{
84+
DisposeSocket();
85+
}
86+
}
87+
88+
/// <inheritdoc/>
89+
public void Dispose()
90+
{
91+
Dispose(true);
92+
GC.SuppressFinalize(this);
8393
}
8494

8595
private void DisposeSocket()

0 commit comments

Comments
 (0)