Skip to content

.NET Core

Coralogix offers an easy .NET native integration in the form of an SDK using our open-source code.

Prerequisites

- Get your Coralogix endpoint URL from the [Coralogix Bulk Logs](../../../integrations/coralogix-endpoints.md#coralogix-rest-api-bulk) endpoint that matches your domain
- Set the 'CORALOGIX_LOG_URL' environment variable to your endpoint URL. You can do this programmatically as shown below:
```cs
Environment.SetEnvironmentVariable("CORALOGIX_LOG_URL", "https://api.eu2.coralogix.com/api/v1/logs");
```

Installation

First, install the SDK using the Package Manager Console

#for .Net framework use this command:
Install-Package Coralogix.SDK 

#For .Net Core use this command:
Install-Package CoralogixCoreSDK

Configuration

This code example demonstrates how to configure the logging object and send messages to it.
This example is taken from our sample project, which you can review here.

using System;

namespace netcore_sdk_example
{
    using CoralogixCoreSDK;
    using System.Threading.Tasks;

    internal class Program
    {
        static void Main(string[] args)
        {
            int i = 0;

            do
            {
                CoralogixLogger coralogixLogger;

                // The common practice is to get an instance of the logger in each class and setting the logger name to the class name.
                //logger name will be used as category unless specified otherwise.
                coralogixLogger = CoralogixLogger.GetLogger("My class");

                // Configure Coralogix SDK. You need to define it only once per process.
                coralogixLogger.Configure("PRIVATE_KEY", "APPLICATION_NAME", "SUBSYSTEM_NAME");

                //Send "Hello World!" message with severity verbose.
                coralogixLogger.Log(Severity.Error, "Hello World Coralogix");
                i++;

                Task.Delay(1000).Wait();
            } while ( i < 10);

        }
    }
}

Need help? We love to assist our customers, simply reach out via our in-app chat, and we will walk you through, step by step.