Documentation Index
Fetch the complete documentation index at: https://docs.honeycomb.io/llms.txt
Use this file to discover all available pages before exploring further.
This example shows how to configure the OpenTelemetry .NET SDK’s logger provider to send logs from a .NET application to Honeycomb or to an OpenTelemetry Collector.
Acquire Dependencies
Install the OpenTelemetry SDK and OTLP exporter packages:dotnet add package OpenTelemetry
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol
Configure the Logger Provider
During application setup, create and configure the logger provider:using Microsoft.Extensions.Logging;
using OpenTelemetry;
using OpenTelemetry.Logs;
// Configure a logger factory with OpenTelemetry and the OTLP log exporter
using var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddOpenTelemetry(options =>
{
options.AddOtlpExporter();
});
});
// Create an ILogger instance from the logger factory
var logger = loggerFactory.CreateLogger<Program>();
// Use the logger in your application
logger.LogInformation("Something interesting happened");
Run Your Application
Set environment variables to configure the exporter and define your service name, then run your application.To send logs directly to Honeycomb:OTEL_SERVICE_NAME="my-service" \
OTEL_EXPORTER_OTLP_ENDPOINT="https://api.honeycomb.io" \
OTEL_EXPORTER_OTLP_HEADERS="x-honeycomb-team=<your-api-key>" \
dotnet run
To send logs to an OpenTelemetry Collector instead:OTEL_SERVICE_NAME="my-service" \
OTEL_EXPORTER_OTLP_ENDPOINT="my-collector:4317" \
OTEL_EXPORTER_OTLP_INSECURE=true \
dotnet run