Skip to content

Commit e3e71a2

Browse files
committed
Removed obsolete exceptions handlers
The sink had exceptions handlers when log events could not be written. Those handlers wrote an error message using Serilog's SelfLog() facility. This is now done by the Serilog Core when a sink's Emit() and EmitBatchAsync() methods throw an exception. This is why can remove our handlers, let exceptions propagate and Serilog Core do the work.
1 parent 1ad392b commit e3e71a2

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/Platform/SqlBulkBatchWriter.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ public async Task WriteBatch(IEnumerable<LogEvent> events)
6060
}
6161
}
6262
}
63-
catch (Exception ex)
64-
{
65-
SelfLog.WriteLine("Unable to write batch of {0} log events to the database due to following error: {1}",
66-
events.Count(), ex);
67-
throw;
68-
}
6963
finally
7064
{
7165
_dataTable.Clear();

src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/Platform/SqlInsertStatementWriter.cs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,26 @@ public SqlInsertStatementWriter(
4343

4444
public async Task WriteEvents(IEnumerable<LogEvent> events)
4545
{
46-
try
46+
using (var cn = _sqlConnectionFactory.Create())
4747
{
48-
using (var cn = _sqlConnectionFactory.Create())
48+
await cn.OpenAsync().ConfigureAwait(false);
49+
50+
foreach (var logEvent in events)
4951
{
50-
await cn.OpenAsync().ConfigureAwait(false);
52+
var fields = _logEventDataGenerator.GetColumnsAndValues(logEvent).ToList();
53+
InitializeSqlCommand(cn, fields);
5154

52-
foreach (var logEvent in events)
55+
var index = 0;
56+
_sqlCommand.ClearParameters();
57+
foreach (var field in fields)
5358
{
54-
var fields = _logEventDataGenerator.GetColumnsAndValues(logEvent).ToList();
55-
InitializeSqlCommand(cn, fields);
56-
57-
var index = 0;
58-
_sqlCommand.ClearParameters();
59-
foreach (var field in fields)
60-
{
61-
_sqlCommand.AddParameter(Invariant($"@P{index}"), field.Value);
62-
index++;
63-
}
64-
65-
await _sqlCommand.ExecuteNonQueryAsync().ConfigureAwait(false);
59+
_sqlCommand.AddParameter(Invariant($"@P{index}"), field.Value);
60+
index++;
6661
}
62+
63+
await _sqlCommand.ExecuteNonQueryAsync().ConfigureAwait(false);
6764
}
6865
}
69-
catch (Exception ex)
70-
{
71-
SelfLog.WriteLine("Unable to write log event to the database due to following error: {0}", ex);
72-
throw;
73-
}
7466
}
7567

7668
/// <summary>

0 commit comments

Comments
 (0)