Skip to content

Commit

Permalink
Removed obsolete exceptions handlers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ckadluba committed Nov 22, 2024
1 parent 1ad392b commit e3e71a2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ public async Task WriteBatch(IEnumerable<LogEvent> events)
}
}
}
catch (Exception ex)
{
SelfLog.WriteLine("Unable to write batch of {0} log events to the database due to following error: {1}",
events.Count(), ex);
throw;
}
finally
{
_dataTable.Clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,26 @@ public SqlInsertStatementWriter(

public async Task WriteEvents(IEnumerable<LogEvent> events)
{
try
using (var cn = _sqlConnectionFactory.Create())
{
using (var cn = _sqlConnectionFactory.Create())
await cn.OpenAsync().ConfigureAwait(false);

foreach (var logEvent in events)
{
await cn.OpenAsync().ConfigureAwait(false);
var fields = _logEventDataGenerator.GetColumnsAndValues(logEvent).ToList();
InitializeSqlCommand(cn, fields);

foreach (var logEvent in events)
var index = 0;
_sqlCommand.ClearParameters();
foreach (var field in fields)
{
var fields = _logEventDataGenerator.GetColumnsAndValues(logEvent).ToList();
InitializeSqlCommand(cn, fields);

var index = 0;
_sqlCommand.ClearParameters();
foreach (var field in fields)
{
_sqlCommand.AddParameter(Invariant($"@P{index}"), field.Value);
index++;
}

await _sqlCommand.ExecuteNonQueryAsync().ConfigureAwait(false);
_sqlCommand.AddParameter(Invariant($"@P{index}"), field.Value);
index++;
}

await _sqlCommand.ExecuteNonQueryAsync().ConfigureAwait(false);
}
}
catch (Exception ex)
{
SelfLog.WriteLine("Unable to write log event to the database due to following error: {0}", ex);
throw;
}
}

/// <summary>
Expand Down

0 comments on commit e3e71a2

Please sign in to comment.