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() { 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++; diff --git a/source/log4net-loggly/log4net-loggly.csproj b/source/log4net-loggly/log4net-loggly.csproj index 0135e25..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.0 + 9.0.3 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.3 + 9.0.0.3