From 16d05326162d9b8c4a126d184dca63e0e8b17e88 Mon Sep 17 00:00:00 2001 From: Mike Watkins Date: Thu, 25 Apr 2019 08:11:56 -0400 Subject: [PATCH 1/5] Update loggly client to catch all exceptions during send and execute retry logic so as to not cause the client to crash during an unexpected exception. --- source/log4net-loggly/LogglyClient.cs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/source/log4net-loggly/LogglyClient.cs b/source/log4net-loggly/LogglyClient.cs index cb6ef63..3a96f79 100644 --- a/source/log4net-loggly/LogglyClient.cs +++ b/source/log4net-loggly/LogglyClient.cs @@ -32,17 +32,20 @@ public void Send(string[] messagesBuffer, int numberOfMessages) SendToLoggly(message); break; } - catch (WebException e) + catch (Exception e) { - var response = (HttpWebResponse)e.Response; - if (response != null && response.StatusCode == HttpStatusCode.Forbidden) + if (e is WebException) { - _isTokenValid = false; - ErrorReporter.ReportError($"LogglyClient: Provided Loggly customer token '{_config.CustomerToken}' is invalid. No logs will be sent to Loggly."); - } - else - { - ErrorReporter.ReportError($"LogglyClient: Error sending logs to Loggly: {e.Message}"); + var response = ((WebException)e).Response as HttpWebResponse; + if (response != null && response.StatusCode == HttpStatusCode.Forbidden) + { + _isTokenValid = false; + ErrorReporter.ReportError($"LogglyClient: Provided Loggly customer token '{_config.CustomerToken}' is invalid. No logs will be sent to Loggly."); + } + else + { + ErrorReporter.ReportError($"LogglyClient: Error sending logs to Loggly: {e.Message}"); + } } currentRetry++; From 24620dbd250459e4f3796fd5e1fe9688a725c9d1 Mon Sep 17 00:00:00 2001 From: Mike Watkins Date: Thu, 25 Apr 2019 08:20:49 -0400 Subject: [PATCH 2/5] Add unit test to verify that a generic system error executes the same retry logic as a WebException does. --- .../LogglyClientTest.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/source/log4net-loggly.UnitTests/LogglyClientTest.cs b/source/log4net-loggly.UnitTests/LogglyClientTest.cs index 0889887..9b375c7 100644 --- a/source/log4net-loggly.UnitTests/LogglyClientTest.cs +++ b/source/log4net-loggly.UnitTests/LogglyClientTest.cs @@ -92,6 +92,24 @@ public void RetriesSendWhenErrorOccurs() "Generic send error should be retried"); } + [Fact] + public void RetriesSendWhenSystemErrorOccurs() + { + _webRequestMock.Setup(x => x.GetResponse()) + .Throws(new OperationCanceledException("The operation was canceled.")); + + var config = new Config + { + MaxSendRetries = 3 + }; + var client = new LogglyClient(config); + + client.Send(new[] { "test message" }, 1); + + _webRequestMock.Verify(x => x.GetResponse(), Times.Exactly(config.MaxSendRetries + 1), + "Generic system error should be retried"); + } + [Fact] public void SendsCorrectData() { From 83c7a4b03be1229dfc0c1ffa40945c065ec62fde Mon Sep 17 00:00:00 2001 From: Mike Watkins Date: Mon, 28 Oct 2019 08:42:24 -0400 Subject: [PATCH 3/5] Update package version to 9.0.1 --- source/log4net-loggly/log4net-loggly.csproj | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/log4net-loggly/log4net-loggly.csproj b/source/log4net-loggly/log4net-loggly.csproj index 0135e25..1a967f5 100644 --- a/source/log4net-loggly/log4net-loggly.csproj +++ b/source/log4net-loggly/log4net-loggly.csproj @@ -4,7 +4,7 @@ full netstandard2.0;net40 true - 9.0.0 + 9.0.1 Loggly Loggly http://opensource.org/licenses/MIT @@ -14,7 +14,7 @@ - Fixed serialization of logged objects. They are now again serialized as full JSON instead of their .NET type name. - Fixed issue when logicalThreadContextKeys and globalContextKeys were ignored if <layout> definition was used. - - Fixed priority of GlobalContext, ThreadContext, LogicalThreadContext and EventContext properties. It was in reverse order than it should be. Correct priority from highest to lowest is EventContext -> LogicalThreadContext -> ThreadContext -> GlobalContext + - Fixed priority of GlobalContext, ThreadContext, LogicalThreadContext and EventContext properties. It was in reverse order than it should be. Correct priority from highest to lowest is EventContext -> LogicalThreadContext -> ThreadContext -> GlobalContext - Removed option to use Loggly /inputs HTTP endpoint. All logs are sent via /bulk endpoint. - Changed inner exception property names. Previously the exception properties were named "exceptionType, exceptionMessage" etc. but inner exception properties were "innerExceptionType, innerExceptionMessage" etc. This was unified and inner exception properties are now also named "exceptionType, exceptionMessage" etc. - Changed default number of inner exceptions that are sent in log from 1 to 4. @@ -23,6 +23,8 @@ Copyright 2019 Loggly-log4net log4net appender logs log4net.loggly + 9.0.0.1 + 9.0.0.1 From 4802d15e21ffcdd291ec7d1de3917084971c0bca Mon Sep 17 00:00:00 2001 From: Mike Watkins Date: Sat, 30 Jan 2021 08:30:29 -0500 Subject: [PATCH 4/5] Bumping the version number so package creation doesn't fail. --- source/log4net-loggly/log4net-loggly.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/log4net-loggly/log4net-loggly.csproj b/source/log4net-loggly/log4net-loggly.csproj index 1a967f5..93fc76b 100644 --- a/source/log4net-loggly/log4net-loggly.csproj +++ b/source/log4net-loggly/log4net-loggly.csproj @@ -4,7 +4,7 @@ full netstandard2.0;net40 true - 9.0.1 + 9.0.2 Loggly Loggly http://opensource.org/licenses/MIT @@ -23,8 +23,8 @@ Copyright 2019 Loggly-log4net log4net appender logs log4net.loggly - 9.0.0.1 - 9.0.0.1 + 9.0.0.2 + 9.0.0.2 From 58c633a30105eda823185d4f97344ebfd5c2c31a Mon Sep 17 00:00:00 2001 From: Mike Watkins Date: Tue, 22 Jun 2021 16:50:42 -0400 Subject: [PATCH 5/5] Bump version number. --- source/log4net-loggly/log4net-loggly.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/log4net-loggly/log4net-loggly.csproj b/source/log4net-loggly/log4net-loggly.csproj index 93fc76b..25d8d0c 100644 --- a/source/log4net-loggly/log4net-loggly.csproj +++ b/source/log4net-loggly/log4net-loggly.csproj @@ -4,7 +4,7 @@ full netstandard2.0;net40 true - 9.0.2 + 9.0.3 Loggly Loggly http://opensource.org/licenses/MIT @@ -23,8 +23,8 @@ Copyright 2019 Loggly-log4net log4net appender logs log4net.loggly - 9.0.0.2 - 9.0.0.2 + 9.0.0.3 + 9.0.0.3