Skip to content

Commit edaa008

Browse files
committed
Reverted breaking API change
Cannot remove IDisposable from MSSqlServerAuditSink class without bumping major version, so we leave it the same.
1 parent 4c65eb0 commit edaa008

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/MSSqlServerAuditSink.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace Serilog.Sinks.MSSqlServer
2626
/// Writes log events as rows in a table of MSSqlServer database using Audit logic, meaning that each row is synchronously committed
2727
/// and any errors that occur are propagated to the caller.
2828
/// </summary>
29-
public class MSSqlServerAuditSink : ILogEventSink
29+
public class MSSqlServerAuditSink : ILogEventSink, IDisposable
3030
{
3131
private readonly ISqlLogEventWriter _sqlLogEventWriter;
3232

@@ -97,6 +97,25 @@ internal MSSqlServerAuditSink(
9797
public void Emit(LogEvent logEvent) =>
9898
_sqlLogEventWriter.WriteEvent(logEvent);
9999

100+
/// <summary>
101+
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
102+
/// </summary>
103+
public void Dispose()
104+
{
105+
Dispose(true);
106+
GC.SuppressFinalize(this);
107+
}
108+
109+
/// <summary>
110+
/// Releases the unmanaged resources used by the Serilog.Sinks.MSSqlServer.MSSqlServerAuditSink and optionally
111+
/// releases the managed resources.
112+
/// </summary>
113+
/// <param name="disposing">True to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
114+
protected virtual void Dispose(bool disposing)
115+
{
116+
// This class needn't to dispose anything. This is just here for sink interface compatibility.
117+
}
118+
100119
private static void ValidateParameters(MSSqlServerSinkOptions sinkOptions, ColumnOptions columnOptions)
101120
{
102121
if (sinkOptions?.TableName == null)

test/Serilog.Sinks.MSSqlServer.Tests/Sinks/MSSqlServer/MSSqlServerAuditSinkTests.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Data;
34
using Moq;
45
using Serilog.Events;
56
using Serilog.Parsing;
@@ -11,7 +12,7 @@
1112
namespace Serilog.Sinks.MSSqlServer.Tests
1213
{
1314
[Trait(TestCategory.TraitName, TestCategory.Unit)]
14-
public class MSSqlServerAuditSinkTests
15+
public class MSSqlServerAuditSinkTests : IDisposable
1516
{
1617
private readonly MSSqlServerSinkOptions _sinkOptions;
1718
private readonly Serilog.Sinks.MSSqlServer.ColumnOptions _columnOptions;
@@ -22,6 +23,7 @@ public class MSSqlServerAuditSinkTests
2223
private readonly string _tableName = "tableName";
2324
private readonly string _schemaName = "schemaName";
2425
private MSSqlServerAuditSink _sut;
26+
private bool _disposedValue;
2527

2628
public MSSqlServerAuditSinkTests()
2729
{
@@ -161,5 +163,20 @@ private void SetupSut(bool autoCreateSqlDatabase = false, bool autoCreateSqlTabl
161163
_sinkOptions.AutoCreateSqlTable = autoCreateSqlTable;
162164
_sut = new MSSqlServerAuditSink(_sinkOptions, _columnOptions, _sinkDependencies);
163165
}
166+
167+
protected virtual void Dispose(bool disposing)
168+
{
169+
if (!_disposedValue)
170+
{
171+
_sut?.Dispose();
172+
_disposedValue = true;
173+
}
174+
}
175+
176+
public void Dispose()
177+
{
178+
Dispose(disposing: true);
179+
GC.SuppressFinalize(this);
180+
}
164181
}
165182
}

0 commit comments

Comments
 (0)