NLog.Targets.HttpClient
6.1.4-Preview4
dotnet add package NLog.Targets.HttpClient --version 6.1.4-Preview4
NuGet\Install-Package NLog.Targets.HttpClient -Version 6.1.4-Preview4
<PackageReference Include="NLog.Targets.HttpClient" Version="6.1.4-Preview4" />
<PackageVersion Include="NLog.Targets.HttpClient" Version="6.1.4-Preview4" />
<PackageReference Include="NLog.Targets.HttpClient" />
paket add NLog.Targets.HttpClient --version 6.1.4-Preview4
#r "nuget: NLog.Targets.HttpClient, 6.1.4-Preview4"
#:package NLog.Targets.HttpClient@6.1.4-Preview4
#addin nuget:?package=NLog.Targets.HttpClient&version=6.1.4-Preview4&prerelease
#tool nuget:?package=NLog.Targets.HttpClient&version=6.1.4-Preview4&prerelease
NLog.Targets.HttpClient
NLog HttpClient target for sending log events to an HTTP or HTTPS endpoint.
- Supports HTTP POST, GET, and custom HTTP methods.
- Batch multiple log events into a single HTTP request.
- Supports batching as JSON arrays or Newline Delimited JSON (NDJSON).
- GZip compression
- Custom request headers
- HTTP authentication
- Client certificates (mTLS)
- HTTP proxy support.
If having trouble with output, then check NLog InternalLogger for clues. See also Troubleshooting NLog.
Register Extension
NLog will only recognize the type-alias HttpClient when loading from an NLog.config file after registering the extension:
<extensions>
<add assembly="NLog.Targets.HttpClient"/>
</extensions>
Alternative - register from code using the fluent configuration API:
LogManager.Setup().SetupExtensions(ext => {
ext.RegisterTarget<NLog.Targets.HttpClientTarget>();
});
Configuration Example
<targets>
<target xsi:type="HttpClient"
name="http"
url="https://api.example.com/logs"
layout="${json-encode:${message}}" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="http" />
</rules>
Parameters
| Parameter | Default | Description |
|---|---|---|
url |
Required | Destination URL for HTTP requests. |
layout |
Required | Layout used to render log events into the HTTP request body. |
httpMethod |
POST |
HTTP method used when sending requests. |
contentType |
application/json |
Value of the HTTP Content-Type header. |
keepAlive |
true |
Keeps HTTP connections open for reuse in subsequent requests to improve performance. |
expect100Continue |
false |
Enables the HTTP Expect: 100-continue handshake before sending the request body. |
sendTimeoutSeconds |
30 |
HTTP request timeout in seconds. |
headers |
Additional HTTP request headers. |
| Batching and Retry | Default | Description |
|---|---|---|
batchSize |
1 |
Maximum number of log events to send in a single HTTP payload. |
compress |
None |
Optional payload compression. Supports None, GZip, and GZipFast. |
lineEnding |
LF |
Line separator used when batching log events. |
batchAsJsonArray |
false |
Wraps batched log events in a JSON array instead of separating them with lineEnding. |
maxPayloadSizeBytes |
40960 |
Max payload size before splitting into multiple HTTP requests. Remember BatchSize |
taskDelayMilliseconds |
1 |
Delay before processing queued log events. Higher value can improve batching |
taskTimeoutSeconds |
150 |
Maximum time in seconds before cancellation of HTTP request. |
retryCount |
0 |
Number of retry attempts for failed write operations. |
retryDelayMilliseconds |
2500 |
Initial delay before retry after failed request. Delay doubles for each retry. |
queueLimit |
10000 |
Maximum number of pending log events allowed in the internal queue. |
overflowAction |
Discard |
Action taken when the internal request queue reaches its limit. |
| Authentication and Security | Default | Description |
|---|---|---|
networkUserName |
Username for HTTP authentication. networkUserName = "" means default NTLM credentials. |
|
networkPassword |
Password for HTTP authentication. | |
sslCertificateFile |
Client certificate file used for mutual TLS authentication. | |
sslCertificatePassword |
Password for the client certificate. | |
proxyUrl |
Proxy server URL. | |
proxyUser |
Proxy authentication username. | |
proxyPassword |
Proxy authentication password. |
Custom Headers
Additional HTTP headers can be configured:
<target xsi:type="HttpClient"
name="http"
url="https://api.example.com/logs">
<header name="X-Api-Key" layout="${gdc:item=ApiKey}" />
<header name="X-Environment" layout="Production" />
</target>
Client Certificates (mTLS)
Mutual TLS authentication can be enabled using a client certificate:
<target xsi:type="HttpClient"
name="http"
url="https://secure.example.com/logs"
sslCertificateFile="client.pfx"
sslCertificatePassword="secret" />
Retry Behavior
The target treats the following status codes as transient failures, that can be retried:
- 408 Request Timeout
- 429 Too Many Requests
- 5xx Server Errors
Client-side failures such as 400 Bad Request are not retried.
Splunk HTTP Event Collector (HEC)
SplunkLayout from the NLog.Targets.Network package can be used together with the HttpClient target to send events to the Splunk HEC /services/collector/event endpoint using newline-delimited JSON (NDJSON).
SplunkLayout renders the complete HEC event, including the outer time, host, source, sourcetype, index, and nested event fields.
The Authorization header is mandatory for Splunk HEC: Authorization: Splunk <hec-token>
<nlog>
<extensions>
<add assembly="NLog.Targets.HttpClient"/>
<add assembly="NLog.Targets.Network"/>
</extensions>
<targets>
<target xsi:type="HttpClient"
name="splunk"
url="https://splunk-host:8088/services/collector/event"
batchSize="100">
<layout xsi:type="SplunkLayout" />
<header name="Authorization" layout="Splunk ${configsetting:Splunk.Token}" />
</target>
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="splunk" />
</rules>
</nlog>
Notes
- The target internally reuses a single
HttpClientinstance to take advantage of connection pooling. - The
HttpClientinstance is periodically recycled (every 5 minutes) to detect DNS changes while still benefiting from pooled connections.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 is compatible. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
NuGet packages (1)
Showing the top 1 NuGet packages that depend on NLog.Targets.HttpClient:
| Package | Downloads |
|---|---|
|
NLog.Targets.OpenTelemetryHttp
NLog OpenTelemetryHttpTarget for sending log events to OpenTelemetry HTTP endpoint using protobuf (OTLP/HTTP). |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 6.1.4-Preview4 | 34 | 7/13/2026 |
| 6.1.4-Preview3 | 89 | 7/9/2026 |
| 6.0.5-Preview2 | 292 | 6/22/2026 |
| 6.0.5-Preview1 | 42 | 6/20/2026 |
Changelog:
- Preview4 Release of HttpClientTarget.