A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://nuget.org/packages/Serilog.Sinks.AzureDataExplorer below:

NuGet Gallery | Serilog.Sinks.AzureDataExplorer 2.0.0

A Serilog sink that writes events to an Azure Data Explorer (Kusto) cluster.

Package - Serilog.Sinks.AzureDataExplorer | Platforms - .NET 9.0, .NET 8.0, .NET 6.0, .NET Standard 2.0

Getting started

Install from NuGet:

Install-Package Serilog.Sinks.AzureDataExplorer
How to use

This sink supports the durable mode where the logs are written to a file first and then flushed to the specified ADX table. This durable mode prevents data loss when the ADX connection couldnt be established. Durable mode can be turned on when we specify the bufferFileName in the LoggerConfiguration as mentioned below.

Configuration when durable mode is not required

var log = new LoggerConfiguration()
    .WriteTo.AzureDataExplorer(new AzureDataExplorerSinkOptions
    {
        IngestionEndpointUri = "https://ingest-mycluster.northeurope.kusto.windows.net",
        DatabaseName = "MyDatabase",
        TableName = "Serilogs"
    })
    .CreateLogger();

Configuration when durable mode is required

var log = new LoggerConfiguration()
    .WriteTo.AzureDataExplorer(new AzureDataExplorerSinkOptions
    {
        IngestionEndpointUri = "https://ingest-mycluster.northeurope.kusto.windows.net",
        DatabaseName = "MyDatabase",
        TableName = "Serilogs",
        BufferBaseFileName = "BufferBaseFileName",
        BufferFileRollingInterval = RollingInterval.Minute
    })
    .CreateLogger();

Note: Inorder to get the exception as string mapped to kusto column such as Exception, it is recommended to use ExceptionEx Attribute. For example:

new SinkColumnMapping { ColumnName ="Exception", ColumnType ="string", ValuePath = "$.ExceptionEx" }
Configuration of Azure Data Explorer Serilog sink through appsettings.json

You can configure the Azure Data Explorer Serilog Sink using an appsettings.json file. Below is a sample appsettings.json file that includes the Periodic Batching configuration options: batchPostingLimit, period, and queueSizeLimit.

Sample appsettings.json contents

{
  "Serilog": {
    "Using": [ "Serilog.Sinks.AzureDataExplorer" ],
    "MinimumLevel": "Verbose",
    "WriteTo": [
      {
        "Name": "AzureDataExplorerSink",
        "Args": {
          "ingestionUri": "https://ingest-cluster-name",
          "databaseName": "sample",
          "tableName": "table",
          "applicationClientId": "xxxxxxxx",
          "applicationSecret": "xxxxxxx",
          "tenantId": "xxxxxxx",
          "isManagedIdentity": false,
          "isWorkloadIdentity": false,
          "batchPostingLimit": 1000,  // Optional
          "period": 10.0,             // Optional (in seconds)
          "queueSizeLimit": 100000    // Optional
        }
      }
    ]
  }
}
Configuration of Azure Data Explorer Serilog sink through appsettings.xml

You can also configure the Azure Data Explorer Serilog Sink using an appsettings.xml file.

Sample appsettings.xml contents

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <Serilog>
    <Using>Serilog.Sinks.File</Using>
    <Using>Serilog.Sinks.AzureDataExplorer</Using>
    <MinimumLevel Default="Verbose" />
    <WriteTo>
      <Args>
        <Name>AzureDataExplorerSink</Name>
        <Args>
          <ingestionUri>https://ingest-cluster-name</ingestionUri>
          <databaseName>DatabaseName</databaseName>
          <tableName>TableName</tableName>
          <applicationClientId>YOUR_CLIENT_ID</applicationClientId> 
          <applicationSecret>YOUR_APP_SECRET</applicationSecret> 
          <tenantId>YOUR_TENANT_ID</tenantId> 
          <batchPostingLimit>1000</batchPostingLimit> 
          <period>10</period> 
          <queueSizeLimit>100000</queueSizeLimit> 
        </Args>
      </Args>
    </WriteTo>
  </Serilog>
</configuration>

Parameters for Periodic Batching:

batchPostingLimit: Specifies the maximum number of events to include in a batch. Defaults to 1000.

period: Specifies the time in seconds between checking for event batches to post. Defaults to 10 seconds.

queueSizeLimit: Specifies the maximum number of events in the queue. Once this limit is reached, new events will be dropped until the queue size decreases. Defaults to 100000.

The appsettings.json can be loaded through the following piece of code

var configuration = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
            .Build();

var logger = new LoggerConfiguration()
            .ReadFrom.Configuration(configuration)
            .CreateLogger();

Required NuGet Packages

Ensure you have the following NuGet dependencies to enable configuration through appsettings.json:

Features Options Batching Target ADX Cluster Mapping

Azure Data Explorer provides data mapping capabilities, allowing the ability to extract data rom the ingested JSONs as part of the ingestion. This allows paying a one-time cost of processing the JSON during ingestion, and reduced cost at query time.

By default, the sink uses the following data mapping:

Column Name Column Type JSON Path Timestamp datetime $.Timestamp Level string $.Level Message string $.Message Exception string $.Exception Properties dynamic $.Properties

This mapping can be overridden using the following options:

Durable Mode

Durable mode can be turned on when we specify the bufferFileName in the LoggerConfiguration. There are few other options available when the durable mode is enabled.

Authentication

The sink supports authentication using various methods. Use one of the following methods to configure the desired authentication methods:

new AzureDataExplorerSinkOptions()
    .WithXXX(...)
Mode Method Notes AadUserPrompt WithAadUserPrompt Recommended only development! AadUserToken WithAadUserToken AadApplicationCertificate WithAadApplicationCertificate AadApplicationKey WithAadApplicationKey AadApplicationSubjectName WithAadApplicationSubjectName AadApplicationThumbprint WithAadApplicationThumbprint AadApplicationToken WithAadApplicationToken AadAzureTokenCredentials WithAadAzureTokenCredentials AadUserManagedIdentity WithAadUserManagedIdentity AadSystemManagedIdentity WithAadSystemManagedIdentity AadWorkloadIdentity WithWorkloadIdentity

Note that if none of the authentication options are provided, AzCliIdentity , followed by AadUserPrompt will be attempted.

V2.0.0:
     - Added multi-target framework support for .NET 6.0 and .NET 8.0
     - Updated dependencies and improved compatibility
     - Enhanced CI/CD pipeline with test matrix for both .NET versions

           Previous releases:


     - Added GZip compression when sending data
     - Improved options default values
     - Added durability to the Azure Data Explorer Sink
     - Added Sample project
     - Added unit Tests
     - Added End To End Test cases


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4