NLog.Targets.HttpClient
6.2.2
dotnet add package NLog.Targets.HttpClient --version 6.2.2
NuGet\Install-Package NLog.Targets.HttpClient -Version 6.2.2
<PackageReference Include="NLog.Targets.HttpClient" Version="6.2.2" />
<PackageVersion Include="NLog.Targets.HttpClient" Version="6.2.2" />
<PackageReference Include="NLog.Targets.HttpClient" />
paket add NLog.Targets.HttpClient --version 6.2.2
#r "nuget: NLog.Targets.HttpClient, 6.2.2"
#:package NLog.Targets.HttpClient@6.2.2
#addin nuget:?package=NLog.Targets.HttpClient&version=6.2.2
#tool nuget:?package=NLog.Targets.HttpClient&version=6.2.2
NLog.Targets.HttpClient
The NLog HttpClient target sends log events to HTTP or HTTPS endpoints.
- Supports HTTP POST, GET, and custom HTTP methods.
- Supports batching multiple log events into a single HTTP request.
- Supports batching as JSON arrays or newline-delimited JSON (NDJSON).
- Supports GZip compression.
- Supports custom request headers.
- Supports HTTP authentication.
- Supports client certificates (mTLS).
- Supports HTTP proxies.
If you have trouble with output, check NLog InternalLogger for clues. See also Troubleshooting NLog.
Register Extension
The HttpClient type alias is available in an NLog.config file after registering the extension:
<extensions>
<add assembly="NLog.Targets.HttpClient"/>
</extensions>
Alternatively, register it in code using the fluent configuration API:
LogManager.Setup().SetupExtensions(ext => {
ext.RegisterTarget<NLog.Targets.HttpClientTarget>();
});
Configuration Example
HttpClient and JsonLayout can be used together to send structured log events to HTTP endpoints that accept JSON or newline-delimited JSON (NDJSON), including log collectors such as Fluentd, Fluent Bit, Logstash, and Vector.
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<extensions>
<add assembly="NLog.Targets.HttpClient"/>
</extensions>
<targets>
<target xsi:type="HttpClient"
name="http"
url="http://localhost:9880/logs_api"
contentType="application/x-ndjson"
batchSize="100">
<header name="User-Agent" layout="NLog-Http-${appdomain:friendly}" />
<layout xsi:type="JsonLayout" includeEventProperties="true">
<attribute name="timestamp" layout="${date:format=o:universalTime=true}" />
<attribute name="hostname" layout="${hostname}" />
<attribute name="application" layout="${processname}" />
<attribute name="level" layout="${level}" />
<attribute name="message" layout="${message:withException=true}" />
</layout>
</target>
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="http" />
</rules>
</nlog>
Parameters
| Parameter | Default | Description |
|---|---|---|
| url | Required | Endpoint URL for HTTP or HTTPS 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. |
| headers | Additional HTTP request headers. |
| Batching and Retry | Default | Description |
|---|---|---|
| batchSize | 1 |
Maximum number of log events to send in a single HTTP payload. Increase on high-latency connections. |
| compress | None |
Optional compression of the HTTP request payload. Supports None, GZip, and GZipFast. |
| lineEnding | LF |
Line separator used between log events when batching. |
| batchAsJsonArray | false |
Wraps batched log events in a JSON array instead of separating them with lineEnding. |
| maxPayloadSizeBytes | 40960 |
Maximum payload size in bytes before splitting into multiple HTTP requests when using batchSize. |
| taskDelayMilliseconds | 1 |
Delay before processing queued log events. Increasing value can improve batching. |
| taskTimeoutSeconds | 150 |
Maximum lifetime in seconds for the entire task performing the 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 queue reaches its limit (Grow / Block / Discard). |
| Network and Security | Default | Description |
|---|---|---|
| keepAlive | true |
Keeps HTTP connections open for reuse by subsequent requests for better performance. |
| expect100Continue | false |
Enables the HTTP 100-Continue handshake before sending the request body, but can increase latency. |
| sendTimeoutSeconds | 30 |
HTTP request timeout in seconds. |
| networkUserName | Username for HTTP authentication. Explicit blank value (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 file. | |
| sslCertificateThumbprint | Thumbprint of a client certificate from X509Store (CurrentUser, then LocalMachine). Alternative to sslCertificateFile. |
|
| proxyUrl | Proxy server URL. | |
| proxyUser | Proxy authentication username. | |
| proxyPassword | Proxy authentication password. |
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 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<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">
<header name="Authorization" layout="Splunk ${configsetting:Splunk.Token}" />
<layout xsi:type="SplunkLayout" />
</target>
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="splunk" />
</rules>
</nlog>
OpenSearch Bulk API
EcsLayout from the Elastic.CommonSchema.NLog can be used together with the HttpClient target to send ECS-formatted log events to OpenSearch using the Bulk API.
EcsLayout produces the ECS-formatted JSON document, while CompoundLayout adds the Bulk API action metadata. The 
 is an explicit LF required to separate the action and document lines in the NDJSON payload for Bulk API. The URL /logs/_bulk supplies the default target index, so the Bulk API action does not need to provide an index value.
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<extensions>
<add assembly="NLog.Targets.HttpClient"/>
<add assembly="Elastic.CommonSchema.NLog"/>
</extensions>
<targets>
<target xsi:type="HttpClient"
name="opensearch"
url="https://localhost:9200/logs/_bulk"
contentType="application/x-ndjson"
batchSize="100">
<layout xsi:type="CompoundLayout">
<layout xsi:type="SimpleLayout" text="{"index":{}}
" />
<layout xsi:type="EcsLayout" />
</layout>
</target>
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="opensearch" />
</rules>
</nlog>
For production use, consider targeting a write index alias managed by your rollover/index lifecycle strategy rather than a permanently fixed index name. Authentication can be configured using the standard HttpClient target authentication and header options.
Note that the OpenSearch Bulk API can return HTTP 200 even when some bulk operations fail. The HttpClient target retries requests based on the HTTP status code, but does not inspect the Bulk API response body for per-document failures.
Log export depends on an in-memory queue, so log events can be lost if the application crashes or exits without a proper flush or shutdown. For stronger delivery guarantees, consider using Elastic.CommonSchema.NLog with the NLog FileTarget, then use Fluent Bit (AWS FireLens) or Data Prepper to forward the logs to OpenSearch.
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" />
Alternatively, load the client certificate from the Windows certificate store by thumbprint:
<target xsi:type="HttpClient"
name="http"
url="https://secure.example.com/logs"
sslCertificateThumbprint="A1B2C3D4E5F6..." />
Retry Behavior
The target treats the following HTTP response 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.
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.
Update NLog dependency to 6.2.2.