Skip to content

Commit e0cb12a

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 e0cb12a

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-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: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace Serilog.Sinks.MSSqlServer.Tests
1212
{
1313
[Trait(TestCategory.TraitName, TestCategory.Unit)]
14-
public class MSSqlServerAuditSinkTests
14+
public class MSSqlServerAuditSinkTests : IDisposable
1515
{
1616
private readonly MSSqlServerSinkOptions _sinkOptions;
1717
private readonly Serilog.Sinks.MSSqlServer.ColumnOptions _columnOptions;
@@ -22,6 +22,7 @@ public class MSSqlServerAuditSinkTests
2222
private readonly string _tableName = "tableName";
2323
private readonly string _schemaName = "schemaName";
2424
private MSSqlServerAuditSink _sut;
25+
private bool _disposedValue;
2526

2627
public MSSqlServerAuditSinkTests()
2728
{
@@ -161,5 +162,20 @@ private void SetupSut(bool autoCreateSqlDatabase = false, bool autoCreateSqlTabl
161162
_sinkOptions.AutoCreateSqlTable = autoCreateSqlTable;
162163
_sut = new MSSqlServerAuditSink(_sinkOptions, _columnOptions, _sinkDependencies);
163164
}
165+
166+
protected virtual void Dispose(bool disposing)
167+
{
168+
if (!_disposedValue)
169+
{
170+
_sut?.Dispose();
171+
_disposedValue = true;
172+
}
173+
}
174+
175+
public void Dispose()
176+
{
177+
Dispose(disposing: true);
178+
GC.SuppressFinalize(this);
179+
}
164180
}
165181
}

0 commit comments

Comments
 (0)