Skip to content

Commit

Permalink
Merge pull request #180 from nblumhardt/limit-pooled-connection-lifetime
Browse files Browse the repository at this point in the history
Limit the default pooled connection lifetime on .NET 5 and greater
  • Loading branch information
nblumhardt authored Sep 12, 2022
2 parents c856c94 + 042e79c commit 386b044
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Serilog.Sinks.Seq/Serilog.Sinks.Seq.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
<DefineConstants>$(DefineConstants);DURABLE;THREADING_TIMER;WRITE_ALL_BYTES_ASYNC</DefineConstants>
<DefineConstants>$(DefineConstants);DURABLE;THREADING_TIMER;WRITE_ALL_BYTES_ASYNC;SOCKETS_HTTP_HANDLER_ALWAYS_DEFAULT</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net4.5' ">
Expand Down
18 changes: 17 additions & 1 deletion src/Serilog.Sinks.Seq/Sinks/Seq/Http/SeqIngestionApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,23 @@ public SeqIngestionApiClient(string serverUrl, string? apiKey, HttpMessageHandle
{
if (serverUrl == null) throw new ArgumentNullException(nameof(serverUrl));
_apiKey = apiKey;
_httpClient = messageHandler != null ? new HttpClient(messageHandler) : new HttpClient();
_httpClient = messageHandler != null
? new HttpClient(messageHandler)
:
#if SOCKETS_HTTP_HANDLER_ALWAYS_DEFAULT
new HttpClient(new SocketsHttpHandler
{
// The default value is infinite; this causes problems for long-running processes if DNS changes
// require that the Seq API be accessed at a different IP address. Setting a timeout here puts
// an upper bound on the duration of DNS-related outages, while hopefully incurring only infrequent
// connection reestablishment costs.
PooledConnectionLifetime = TimeSpan.FromMinutes(5)
})
#else
new HttpClient()
#endif
;

_httpClient.BaseAddress = new Uri(NormalizeServerBaseAddress(serverUrl));
}

Expand Down

0 comments on commit 386b044

Please sign in to comment.