Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

Commit

Permalink
Added better error handling in LogglySink
Browse files Browse the repository at this point in the history
Updated the EmitBatchAsync method in LogglySink to handle potential exceptions and evaluate the LogResponse when calling the Log method of the LogglyClient.  It now writes to SelfLog when problems occur to enable easier debugging.
  • Loading branch information
danjagnow committed Jul 30, 2020
1 parent 1fd9a0a commit 7073741
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Linq;
using System.Threading.Tasks;
using Loggly;
using Serilog.Debugging;
using Serilog.Events;
using Serilog.Sinks.PeriodicBatching;

Expand Down Expand Up @@ -80,7 +81,24 @@ public LogglySink(IFormatProvider formatProvider, int batchSizeLimit, TimeSpan p
/// not both.</remarks>
protected override async Task EmitBatchAsync(IEnumerable<LogEvent> events)
{
await _client.Log(events.Select(_converter.CreateLogglyEvent));
try
{
LogResponse response = await _client.Log(events.Select(_converter.CreateLogglyEvent)).ConfigureAwait(false);

switch (response.Code)
{
case ResponseCode.Error:
SelfLog.WriteLine("LogglySink received an Error response: {0}", response.Message);
break;
case ResponseCode.Unknown:
SelfLog.WriteLine("LogglySink received an Unknown response: {0}", response.Message);
break;
}
}
catch (Exception ex)
{
SelfLog.WriteLine("LogglySink encountered an exception: {0}", ex);
}
}

}
Expand Down

0 comments on commit 7073741

Please sign in to comment.