From 1fd9a0a1355a7557f9780d1b91c23c86f468cb24 Mon Sep 17 00:00:00 2001 From: Dan Jagnow Date: Thu, 30 Jul 2020 12:31:59 -0500 Subject: [PATCH 1/3] Build fix for sampleDurableLogger.csproj Removed a digit from the PackageReference for Serilog.Sinks.RollingFileAlternate in sampleDurableLogger.csproj to get local builds working. --- sample/sampleDurableLogger/sampleDurableLogger.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample/sampleDurableLogger/sampleDurableLogger.csproj b/sample/sampleDurableLogger/sampleDurableLogger.csproj index 711e7fc..60d199e 100644 --- a/sample/sampleDurableLogger/sampleDurableLogger.csproj +++ b/sample/sampleDurableLogger/sampleDurableLogger.csproj @@ -21,7 +21,7 @@ - + From 7073741717d85451792a4f861a6777858946c4a0 Mon Sep 17 00:00:00 2001 From: Dan Jagnow Date: Thu, 30 Jul 2020 12:34:46 -0500 Subject: [PATCH 2/3] Added better error handling in LogglySink 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. --- .../Sinks/Loggly/LogglySink.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs index 149fc1b..b232e57 100644 --- a/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs +++ b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs @@ -17,6 +17,7 @@ using System.Linq; using System.Threading.Tasks; using Loggly; +using Serilog.Debugging; using Serilog.Events; using Serilog.Sinks.PeriodicBatching; @@ -80,7 +81,24 @@ public LogglySink(IFormatProvider formatProvider, int batchSizeLimit, TimeSpan p /// not both. protected override async Task EmitBatchAsync(IEnumerable 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); + } } } From f37a36cd6c2d0336598180cab1582f328df28c8a Mon Sep 17 00:00:00 2001 From: Dan Jagnow Date: Tue, 18 Aug 2020 18:53:04 -0500 Subject: [PATCH 3/3] Removed try/catch block in LogglySink Removed the try/catch block in the EmitBatchAsync method of LogglySink to allow Serilog to handle exceptions centrally, based on PR feedback. --- .../Sinks/Loggly/LogglySink.cs | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs index b232e57..72c02cd 100644 --- a/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs +++ b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs @@ -81,23 +81,16 @@ public LogglySink(IFormatProvider formatProvider, int batchSizeLimit, TimeSpan p /// not both. protected override async Task EmitBatchAsync(IEnumerable events) { - try - { - LogResponse response = await _client.Log(events.Select(_converter.CreateLogglyEvent)).ConfigureAwait(false); + 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) + switch (response.Code) { - SelfLog.WriteLine("LogglySink encountered an exception: {0}", ex); + 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; } }