> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tracelit.io/llms.txt
> Use this file to discover all available pages before exploring further.

# .NET [Logs]

> OpenTelemetry for ASP.NET Core on Tracelit — ILogger and Serilog.

## 1. Environment

```bash theme={null}
OTEL_SERVICE_NAME=my-service
OTEL_RESOURCE_ATTRIBUTES=deployment.environment=production
OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.tracelit.app
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer <WORKSPACE_INGEST_KEY>
```

## 2. Packages

```bash theme={null}
dotnet add package OpenTelemetry.Extensions.Hosting
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol
dotnet add package OpenTelemetry.Instrumentation.AspNetCore
dotnet add package OpenTelemetry.Instrumentation.Http
```

## 3. Program.cs

```csharp theme={null}
builder.Services.AddOpenTelemetry()
    .ConfigureResource(r => r.AddService(builder.Environment.ApplicationName))
    .WithTracing(t => t
        .AddAspNetCoreInstrumentation()
        .AddHttpClientInstrumentation()
        .AddOtlpExporter())
    .WithLogging(l => l.AddOtlpExporter());
```

<Warning>
  Without `WithLogging()`, you get traces/metrics only — onboarding will wait forever for INFO/ERROR logs.
</Warning>

## 4. Log libraries

<Tabs>
  <Tab title="ILogger">
    With `WithLogging().AddOtlpExporter()` registered, inject `ILogger<T>` as usual:

    ```csharp theme={null}
    _logger.LogInformation("order listed {Count}", 3);
    _logger.LogError(ex, "payment failed");
    ```
  </Tab>

  <Tab title="Serilog">
    ### Install

    ```bash theme={null}
    dotnet add package Serilog.Sinks.OpenTelemetry
    ```

    Configure the sink with the same OTLP endpoint, protocol (`http/protobuf`), and `Authorization` header as your tracer.

    ```csharp theme={null}
    _logger.Information("order listed {Count}", 3);
    _logger.Error(ex, "payment failed");
    ```
  </Tab>
</Tabs>

## 5. Verify

Produce **one INFO log** and **one ERROR log**, then confirm both in Tracelit Logs (or the onboarding live preview).
