Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fintegrations%2Fsdks%2Fdotnet-logging.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fintegrations%2Fsdks%2Fdotnet-logging.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

Warning

**Deprecation Notice**: The Coralogix .NET SDK (`Coralogix.SDK`, `CoralogixCoreSDK`) will be deprecated in favor of the [OpenTelemetry .NET SDK](https://opentelemetry.io/docs/languages/dotnet/) and will no longer be supported after **June 30, 2026**. See the [end-of-life notice](https://coralogix.com/docs/docs/user-guides/latest-updates/deprecations/dotnet-sdk-deprecation/.md) for migration details.

# .NET

This guide shows how to send .NET application logs to Coralogix using the [OpenTelemetry .NET SDK](https://opentelemetry.io/docs/languages/dotnet/) with `Microsoft.Extensions.Logging`, the OTLP log exporter, and a `Resource` that sets `service.name`, `cx.application.name`, and `cx.subsystem.name`. This replaces shipping logs through the legacy Coralogix .NET SDK.

Use a supported [.NET](https://dotnet.microsoft.com/download) version (8.0 or later is recommended) with current `OpenTelemetry.*` packages.

## Package dependencies setup[​](#package-dependencies-setup "Direct link to Package dependencies setup")

Create a console application and add the OpenTelemetry SDK, OTLP exporter, and logging packages (versions are examples; use the latest compatible releases from NuGet):

```
dotnet new console -n DotnetOtelLogsSample -o DotnetOtelLogsSample

cd DotnetOtelLogsSample

dotnet add package OpenTelemetry --version 1.15.3

dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol --version 1.15.3

dotnet add package Microsoft.Extensions.Logging --version 8.0.0
```

Select the <!-- -->https\://ingress. endpoint that corresponds to your Coralogix [domain](https://coralogix.com/docs/docs/user-guides/account-management/account-settings/coralogix-domain/.md) using the domain selector at the top of the page.

## Application implementation[​](#application-implementation "Direct link to Application implementation")

1. Build a `ResourceBuilder` with `AddService` for `service.name` (and version), then add `cx.application.name` and `cx.subsystem.name` as resource attributes.
2. Call `LoggerFactory.Create` with `AddOpenTelemetry` and `AddOtlpExporter`, pointing at your OTLP/gRPC endpoint (the sample defaults to `http://localhost:4317` for a local collector).
3. Create an `ILogger` with a category name (for example the class name). Emit logs at the level you need; the sample uses `LogError` to match a simple smoke test.

Replace `Program.cs` with the following:

```
using System;

using System.Collections.Generic;

using System.Threading;

using Microsoft.Extensions.Logging;

using OpenTelemetry.Logs;

using OpenTelemetry.Resources;



namespace DotnetOtelLogsSample;



internal static class Program

{

    private static void Main()

    {

        var endpoint = Environment.GetEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT")

            ?? "http://localhost:4317";

        var serviceName = Environment.GetEnvironmentVariable("OTEL_SERVICE_NAME")

            ?? "dotnet-otel-logs-sample";

        var applicationName = Environment.GetEnvironmentVariable("CORALOGIX_APPLICATION")

            ?? "dotnet-otel-app";

        var subsystemName = Environment.GetEnvironmentVariable("CORALOGIX_SUBSYSTEM")

            ?? "worker";



        var resourceBuilder = ResourceBuilder.CreateDefault()

            .AddService(serviceName: serviceName, serviceVersion: "1.0.0")

            .AddAttributes(new Dictionary<string, object>

            {

                ["cx.application.name"] = applicationName,

                ["cx.subsystem.name"] = subsystemName,

            });



        using var loggerFactory = LoggerFactory.Create(builder =>

        {

            builder.AddOpenTelemetry(logging =>

            {

                logging.SetResourceBuilder(resourceBuilder);

                logging.AddOtlpExporter(options =>

                {

                    options.Endpoint = new Uri(endpoint);

                });

            });

        });



        var logger = loggerFactory.CreateLogger("My class");



        var i = 0;

        do

        {

            logger.LogError("Hello World Coralogix");

            i++;

            Thread.Sleep(1000);

        } while (i < 5);



        Thread.Sleep(1500);

        Console.WriteLine("Done: flush window completed");

    }

}
```

Run the sample:

```
dotnet run
```

**Notes**

* The OTLP exporter batches records. Keep the process alive briefly after your last log (as in the sample) so batches can export before exit.
* If you upgrade packages, follow the [OpenTelemetry .NET logs documentation](https://opentelemetry.io/docs/languages/dotnet/instrumentation/#logging) for any API or package layout changes.
* For a broader walkthrough (shared resource builders, traces, and metrics), see [.NET OpenTelemetry instrumentation](https://coralogix.com/docs/docs/opentelemetry/instrumentation-options/dotnet-opentelemetry-instrumentation/.md).

### Logging output[​](#logging-output "Direct link to Logging output")

With the OpenTelemetry SDK, you can send logs either to a local [OpenTelemetry Collector](https://coralogix.com/docs/docs/opentelemetry/kubernetes-observability/kubernetes-observability-using-opentelemetry/.md) or directly to Coralogix using an OTLP endpoint.

#### OpenTelemetry Collector[​](#opentelemetry-collector "Direct link to OpenTelemetry Collector")

Set `OTEL_EXPORTER_OTLP_ENDPOINT` to your collector’s OTLP/gRPC address (often `http://localhost:4317` or `http://collector:4317`). With a `debug` exporter on the collector, log records show resource attributes such as `cx.application.name`, `cx.subsystem.name`, and `service.name`, plus the log body and severity.

[![](/docs/assets/images/otel_screenshot-8f4994baf0d0daa1594e3479f6c6f2d2.webp)](https://coralogix.com/docs/docs/assets/images/otel_screenshot-8f4994baf0d0daa1594e3479f6c6f2d2.webp)

#### Coralogix OpenTelemetry endpoint[​](#coralogix-opentelemetry-endpoint "Direct link to Coralogix OpenTelemetry endpoint")

Authenticate with your [Send-Your-Data API key](https://coralogix.com/docs/docs/user-guides/account-management/api-keys/send-your-data-api-key/.md) and point the OTLP exporter at your Coralogix endpoint. The sample reads `CORALOGIX_APPLICATION` and `CORALOGIX_SUBSYSTEM` for `cx.application.name` and `cx.subsystem.name` (defaults match a local collector; override them when sending to Coralogix).

```
OTEL_EXPORTER_OTLP_ENDPOINT=https://ingress.eu2.coralogix.com:443

OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer send_your_data_key"

OTEL_SERVICE_NAME=dotnet-otel-logs-sample

CORALOGIX_APPLICATION=hello

CORALOGIX_SUBSYSTEM=world
```

In **Explore logs**, application and subsystem filters reflect those resource attributes; expanded rows show `logRecord.body`, severity, and `resource.attributes.service.name`.

[![](/docs/assets/images/coralogix_screenshot-4d6b852932b180ea53da92e695ae5d20.webp)](https://coralogix.com/docs/docs/assets/images/coralogix_screenshot-4d6b852932b180ea53da92e695ae5d20.webp)

### Additional resources[​](#additional-resources "Direct link to Additional resources")

|                     |                                                                                             |
| ------------------- | ------------------------------------------------------------------------------------------- |
| OpenTelemetry .NET  | [OpenTelemetry .NET docs](https://opentelemetry.io/docs/languages/dotnet/)                  |
| Coralogix Endpoints | [Coralogix Endpoints](https://coralogix.com/docs/docs/integrations/coralogix-endpoints/.md) |
