OpenTelemetry Logging in .NET Applications: 2026 Setup Guide

Ready to get started?
Try OpenObserve Cloud today for more efficient and performant observability.

Key takeaways: OpenTelemetry logging in .NET gives you vendor-neutral log export via OTLP, automatic TraceId/SpanId correlation on every log record, and a single SDK for logs, metrics, and traces. This guide covers setup with OpenTelemetry.Extensions.Hosting, a copy-paste config for shipping to OpenObserve, and how to correlate logs with distributed traces.
Introduction
Effective logging is crucial for understanding and troubleshooting application behavior. In .NET applications, OpenTelemetry provides a standardized way to collect and export logs alongside traces and metrics.
In this guide you will learn how to implement opentelemetry logging in a .NET 6+ Web API application, compare it to traditional ILogger approaches, and ship logs to OpenObserve - a lightweight observability platform that accepts OTLP natively.
What Is OpenTelemetry Logging?
OpenTelemetry (OTel) is a CNCF project that defines a single, vendor-neutral standard for collecting telemetry signals - logs, traces, and metrics. The logging pillar of OTel is built around a Log Bridge API that connects existing logging frameworks (like Microsoft.Extensions.Logging in .NET) to the OTel pipeline without requiring you to rewrite any log statements. For language-agnostic rules on what to log, see our application logging best practices.
Key concepts:.
- Log Record - the structured data unit emitted by the SDK; it carries severity, body, attributes, and trace context.
- Log Bridge - an adapter that forwards ILogger calls into the OTel log pipeline. In .NET this is wired automatically when you call
AddOpenTelemetry(). - OTLP Exporter - sends log records to any OTLP-compatible backend over HTTP/protobuf or gRPC.
This design means opentelemetry logging sits on top of your existing code rather than replacing it. If you are already using ILogger<T>, zero application code changes are needed to adopt OTel - only the startup configuration changes.
For broader context on how OTel compares to other instrumentation approaches, see opentelemetry vs prometheus.
OpenTelemetry Logging vs Traditional .NET Logging
| Dimension. | Traditional ILogger + Serilog/NLog. | OpenTelemetry Logging. |
|---|---|---|
| Vendor lock-in. | High - each backend needs its own sink package. | None - one OTLP exporter works with any backend. |
| Signal correlation (logs + traces + metrics). | Manual - must copy TraceId into log scopes. | Automatic - OTel stamps TraceId/SpanId on every record. |
| Backend flexibility. | Switch backend = swap sink package + redeploy. | Switch backend = change one endpoint URL. |
| Setup complexity. | Low for simple cases; grows with number of backends. | Slightly higher initial setup; simpler long-term. |
| Sampling support. | Not standard. | Built in via OTel SDK sampling rules. |
If you are evaluating whether to move away from a costly SaaS provider, the datadog pricing comparison page shows how OpenObserve stacks up. For teams running Kubernetes workloads, kubernetes observability tools reviews the broader tooling landscape.
Prerequisites
Before we begin, ensure you have:.
- .NET SDK 6.0 or newer installed.
- An OpenObserve account (use OpenObserve Cloud or a self-hosted installation).
Copy-Paste: .NET OpenTelemetry Logging Setup
Install the required packages:.
dotnet add package OpenTelemetry.Extensions.Hosting --version 1.9.0
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol --version 1.9.0
Then configure the pipeline in Program.cs:.
using OpenTelemetry.Logs;
using OpenTelemetry.Resources;
var builder = WebApplication.CreateBuilder(args);
// Define shared resource attributes
var resourceBuilder = ResourceBuilder.CreateDefault()
.AddService(
serviceName: "OrderProcessingService",
serviceVersion: "2.0.0")
.AddAttributes(new Dictionary<string, object>
{
["deployment.environment"] = "production",
});
// Wire up OpenTelemetry logging via the ILoggingBuilder bridge
builder.Services.AddOpenTelemetry()
.WithLogging(logging =>
{
logging
.SetResourceBuilder(resourceBuilder)
.AddOtlpExporter(otlp =>
{
otlp.Endpoint = new Uri(
"https://api.openobserve.ai/api/{org}/v1/logs");
otlp.Headers =
"Authorization=Basic YOUR_BASE64_ENCODED_TOKEN";
otlp.Protocol =
OpenTelemetry.Exporter.OtlpExportProtocol.HttpProtobuf;
});
});
var app = builder.Build();
app.Run();
Replace
{org}with your OpenObserve organization slug andYOUR_BASE64_ENCODED_TOKENwith your Base64-encodeduser:passwordstring.
Adding Logs to Your Controllers
Your existing ILogger<T> calls are forwarded automatically:.
[ApiController]
[Route("[controller]")]
public class OrderController : ControllerBase
{
private readonly ILogger<OrderController> _logger;
public OrderController(ILogger<OrderController> logger)
{
_logger = logger;
}
[HttpPost]
public async Task<IActionResult> CreateOrder(Order order)
{
_logger.LogInformation(
"Creating order for customer: {CustomerName} with amount: {Amount}",
order.CustomerName,
order.Amount
);
try
{
// Order processing logic...
return Ok(order);
}
catch (Exception ex)
{
_logger.LogError(
ex,
"Failed to create order for customer {CustomerName}",
order.CustomerName
);
throw;
}
}
}
Sending Logs to OpenObserve
OpenObserve accepts logs over OTLP HTTP/protobuf on the following endpoint:.
https://api.openobserve.ai/api/{org}/v1/logs
Required configuration:.
| Setting. | Value. |
|---|---|
Endpoint. |
https://api.openobserve.ai/api/{org}/v1/logs. |
Authorization header. |
Basic <base64(user:password)>. |
Protocol. |
HttpProtobuf. |
For self-hosted deployments the endpoint is http://<host>:<port>/api/{org}/v1/logs. Full ingestion documentation is available at openobserve.ai/docs.
Once logs arrive, OpenObserve indexes every structured field automatically. You can query by severity, service name, or trace ID without any schema migration. This makes it a compelling alternative when datadog pricing becomes a bottleneck, and it pairs naturally with llm observability pipelines that need a unified log store for inference traces.
Testing Your Setup
dotnet run
# Generate a log by creating an order
curl -X POST http://localhost:5069/order \
-H "Content-Type: application/json" \
-d '{"customerName":"Test User","amount":150.00}'
# Trigger a warning log by requesting a non-existent order
curl http://localhost:5069/order/999
Viewing Logs in OpenObserve
- Log into your OpenObserve instance.
- Navigate to the Logs section.
- You should see a
defaultlogs stream containing order creation attempts, successful orders, and warning logs for non-existent orders.
Correlating Logs with Traces in .NET
One of the biggest advantages of opentelemetry logging over traditional .NET sinks is automatic trace context propagation. The OTel SDK reads Activity.Current at the moment each log record is emitted and stamps the record with the current TraceId and SpanId - no manual scope setup needed.
[HttpPost]
public async Task<IActionResult> CreateOrder(Order order)
{
// This log record is automatically tagged with the active TraceId/SpanId
_logger.LogInformation(
"Creating order for customer: {CustomerName} with amount: {Amount}",
order.CustomerName,
order.Amount
);
using var activity = TracingInstrumentation.ActivitySource
.StartActivity("CreateOrder");
// ... business logic
}
Each log entry includes:.
- Trace ID - links to the corresponding distributed trace.
- Span ID - shows which operation generated the log.
- Service name and version - from the resource builder.
In OpenObserve you can filter logs by trace_id and jump directly to the matching trace waterfall. This end-to-end correlation is especially valuable for teams building llm observability pipelines, where a single inference request may span multiple services and you need to match a slow response log to its trace.

Troubleshooting Common Issues
If you are not seeing logs in OpenObserve:.
- Verify the logs endpoint includes
/v1/logs. - Ensure your Base64-encoded authorization token is correct.
- Make test requests to generate some logs.
- Check console output for any export errors.
- Confirm the protocol is set to
HttpProtobuf(not gRPC) when using the HTTP endpoint.
Next Steps
Now that you have opentelemetry logging running in your .NET application:.
- Watch our detailed video guide on correlating logs with traces for better debugging.
- Follow our .NET tracing guide to implement distributed tracing alongside your logs.
- Explore kubernetes observability tools if you are running your .NET services on Kubernetes.
- Set up log-based alerts, explore structured logging patterns, or add custom attributes to your logs - the complete sample code is available in our GitHub repository.
Need help? Join our Slack community for support.
Try It Free
Ready to see opentelemetry logging in action? Sign up for OpenObserve Cloud - no credit card required. You will have logs, traces, and metrics flowing into a single observability platform in under ten minutes.
Frequently Asked Questions
About the Author
Follow OpenObserve on Google
Add OpenObserve as a preferred source to see more of our articles in Google Search and Top Stories.











