Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute retry logic in Send() method even if exception is not of type WebException #25

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions source/log4net-loggly.UnitTests/LogglyClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
21 changes: 12 additions & 9 deletions source/log4net-loggly/LogglyClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
6 changes: 4 additions & 2 deletions source/log4net-loggly/log4net-loggly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<DebugType>full</DebugType>
<TargetFrameworks>netstandard2.0;net40</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>9.0.0</Version>
<Version>9.0.3</Version>
<Authors>Loggly</Authors>
<Company>Loggly</Company>
<PackageLicenseUrl>http://opensource.org/licenses/MIT</PackageLicenseUrl>
Expand All @@ -14,7 +14,7 @@
<PackageReleaseNotes>
- 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 &lt;layout&gt; 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 -&gt; LogicalThreadContext -&gt; ThreadContext -&gt; 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.
Expand All @@ -23,6 +23,8 @@
<Copyright>Copyright 2019</Copyright>
<PackageTags>Loggly-log4net log4net appender logs</PackageTags>
<RootNamespace>log4net.loggly</RootNamespace>
<AssemblyVersion>9.0.0.3</AssemblyVersion>
<FileVersion>9.0.0.3</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down