Skip to main content
net10.0.NETFramework4.7.1net8.0.NETStandard2.0.NETStandard2.1

NLog OpenTelemetryHttpTarget for sending log events to OpenTelemetry HTTP endpoint using protobuf (OTLP/HTTP).

Published
Sep 18, 2026
2mo ago
Total Downloads
7.8K
7,808

Install

dotnet add package NLog.Targets.OpenTelemetryHttp --version 6.1.5
ProductVersions
.NET
net10.0net8.0
.NET Standard
netstandard2.0netstandard2.1
Other
.NETFramework4.7.1

README

NLog.Targets.OpenTelemetryHttp

Version AppVeyor

NLog OpenTelemetry target for exporting log events to an OpenTelemetry Collector or any OTLP/HTTP-compatible endpoint.

Designed for applications that already use NLog and want to export log events directly using the OTLP protobuf format, without depending on the OpenTelemetry SDK logging pipeline.

Automatically captures TraceId and SpanId for distributed-tracing correlation and exports NLog Event Properties as structured OpenTelemetry log attributes.

If having trouble with output, then check NLog InternalLogger for clues. See also Troubleshooting NLog.

See also:

Register Extension

NLog will only recognize the type-alias OpenTelemetry when loading from an NLog.config file after registering the extension:

<extensions>
    <add assembly="NLog.Targets.OpenTelemetryHttp"/>
</extensions>

Alternative - register from code using the fluent configuration API:

LogManager.Setup().SetupExtensions(ext => {
    ext.RegisterTarget<NLog.Targets.OpenTelemetryHttpTarget>();
});

Configuration Example

Typical endpoint URL is http://localhost:4318/v1/logs.

<nlog>
<extensions>
    <add assembly="NLog.Targets.OpenTelemetryHttp"/>
</extensions>

<targets>
    <target xsi:type="OpenTelemetry"
            name="otlp"
            url="http://localhost:4318/v1/logs" />
</targets>

<rules>
    <logger name="*" minlevel="Info" writeTo="otlp" />
</rules>
</nlog>

Supports the standard OpenTelemetry environment variables as fallback defaults:

  • OTEL_EXPORTER_OTLP_ENDPOINT
  • OTEL_EXPORTER_OTLP_LOGS_ENDPOINT
  • OTEL_EXPORTER_OTLP_HEADERS
  • OTEL_EXPORTER_OTLP_LOGS_HEADERS
  • OTEL_EXPORTER_OTLP_COMPRESSION
  • OTEL_EXPORTER_OTLP_LOGS_COMPRESSION
  • OTEL_EXPORTER_OTLP_TIMEOUT
  • OTEL_EXPORTER_OTLP_LOGS_TIMEOUT
  • OTEL_SERVICE_NAME
  • OTEL_RESOURCE_ATTRIBUTES

Parameters

Parameter Default Description
url OTEL_EXPORTER_OTLP_ENDPOINT OTLP/HTTP endpoint URL (Automatically appends /v1/logs when missing).
layout ${message} Layout used to populate the OpenTelemetry LogRecord.Body field.
traceId ${activity:property=TraceId} Layout used to populate the OpenTelemetry LogRecord.TraceId field.
spanId ${activity:property=SpanId} Layout used to populate the OpenTelemetry LogRecord.SpanId field.
includeEventProperties true Includes NLog event properties as OpenTelemetry log attributes.
scopeName NLog OpenTelemetry instrumentation scope name.
serviceName ${appdomain:format=Friendly} OpenTelemetry service.name resource attribute.
serviceVersion ${assembly-version:Default=} OpenTelemetry service.version resource attribute.
hostName ${hostname} OpenTelemetry host.name resource attribute.
resourceAttributes OTEL_RESOURCE_ATTRIBUTES Additional OpenTelemetry resource attributes.
headers OTEL_EXPORTER_OTLP_HEADERS Additional HTTP headers.
Batching and Retry Default Description
batchSize 200 Maximum number of log events to send in a single HTTP payload.
compress None Optional compression of the OTLP/HTTP request payload. Supports None, GZip, and GZipFast.
maxPayloadSizeBytes 40960 Max payload size before splitting into multiple HTTP requests. Remember BatchSize
taskDelayMilliseconds 50 Delay before processing queued log events. Increasing value can improve batching.
taskTimeoutSeconds 150 Maximum time in seconds before cancellation of HTTP request.
retryCount 3 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.
Network and Security Default Description
sendTimeoutSeconds 30 HTTP request timeout in seconds.
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.

Resource Attributes

Additional OpenTelemetry resource attributes can be configured using resourceAttribute entries:

<target xsi:type="OpenTelemetry" name="otlp">

    <resourceAttribute name="service.namespace" layout="Backend" />
    <resourceAttribute name="deployment.environment" layout="Production" />

</target>

OpenTelemetry Environment Variables

The target automatically resolves standard OpenTelemetry environment variables when equivalent target properties have not been explicitly configured.

Endpoint

Order of precedence:

  1. OTEL_EXPORTER_OTLP_LOGS_ENDPOINT
  2. OTEL_EXPORTER_OTLP_ENDPOINT

When OTEL_EXPORTER_OTLP_ENDPOINT is used, /v1/logs is automatically appended.

Headers

Order of precedence:

  1. OTEL_EXPORTER_OTLP_LOGS_HEADERS
  2. OTEL_EXPORTER_OTLP_HEADERS

Example:

OTEL_EXPORTER_OTLP_HEADERS=api-key=my-secret-key

Compression

Order of precedence:

  1. OTEL_EXPORTER_OTLP_LOGS_COMPRESSION
  2. OTEL_EXPORTER_OTLP_COMPRESSION

Supported values:

  • gzip
  • none

Timeout

Order of precedence:

  1. OTEL_EXPORTER_OTLP_LOGS_TIMEOUT
  2. OTEL_EXPORTER_OTLP_TIMEOUT

Timeout values are specified in milliseconds.

Service Name

OTEL_SERVICE_NAME

Overrides the service.name value from OTEL_RESOURCE_ATTRIBUTES.

Resource Attributes

OTEL_RESOURCE_ATTRIBUTES

Example:

OTEL_RESOURCE_ATTRIBUTES=service.namespace=Backend,deployment.environment=Production

The special attribute:

service.name

is automatically mapped to the serviceName property.

Client Certificate

Order of precedence:

  1. OTEL_EXPORTER_OTLP_LOGS_CLIENT_CERTIFICATE
  2. OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE

Used to configure mutual TLS authentication.

Changes from Previous Version

No structural changes between v6.1.4 and v6.1.5.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

Compatibility metadata lists 5 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.