CB.Serilog.Sinks.AzureLogAnalytics 1.1.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package CB.Serilog.Sinks.AzureLogAnalytics --version 1.1.3                
NuGet\Install-Package CB.Serilog.Sinks.AzureLogAnalytics -Version 1.1.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CB.Serilog.Sinks.AzureLogAnalytics" Version="1.1.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CB.Serilog.Sinks.AzureLogAnalytics --version 1.1.3                
#r "nuget: CB.Serilog.Sinks.AzureLogAnalytics, 1.1.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CB.Serilog.Sinks.AzureLogAnalytics as a Cake Addin
#addin nuget:?package=CB.Serilog.Sinks.AzureLogAnalytics&version=1.1.3

// Install CB.Serilog.Sinks.AzureLogAnalytics as a Cake Tool
#tool nuget:?package=CB.Serilog.Sinks.AzureLogAnalytics&version=1.1.3                

Serilog Sink for Azure Log Analytics

A bare bones custom Serilog sink for Azure Log Analytics. Supports batching of logs. Utilizes the Azure.Monitor.Ingestion library for ingestion to Log Analytics.

Prerequisites

  1. Azure Subscription
  2. Log Analytics workspace provisioned
  3. A configured data collection endpoint and data collection rule in Azure with appropriate permissions.

Get Started

Install package

dotnet add package CB.Serilog.Sinks.AzureLogAnalytics

Authenticate with Azure

By default, a DefaultAzureCredential is used to authenticate with Azure and no additional code is needed. Optionally, a TokenCredential can be passed in for use.

Configure

The sink can be configured programatticaly or through Serilog Serilog.Settings.Configuration NuGet package. An instance of AzureLogAnalyticsSinkConfiguration is required.

App Config Example program.cs

Host.CreateDefaultBuilder()
    .UseSerilog((hostingContext, services, loggerConfiguration) =>
    {
        var assemblies = new[] { typeof(AzureLogAnalyticsSink).Assembly };
        var options = new ConfigurationReaderOptions(assemblies);
        loggerConfiguration
        .Enrich.FromLogContext()
        .ReadFrom.Configuration(hostingContext.Configuration, options);
    });

app.config.json

 "Serilog": {
    "Using": [ "Serilog.Sinks.AzureLogAnalytics" ],
    "MinimumLevel": "Verbose",
    "WriteTo": [
      {
        "Name": "AzureLogAnalytics",
        "Args": {
          "DataCollectionEndpointUri": "<data-collection-endpoint>",
          "RuleId": "<rule-id>",
          "StreamName": "<stream-name>",
          "OutputToConsole": true,
          "MaxLogEntries": 5
        }
      }
    ]
  }
IHostBuilder Example

program.cs

Host.CreateDefaultBuilder()
    .UseSerilog((hostingContext, services, loggerConfiguration) =>
    {
        loggerConfiguration
        .Enrich.FromLogContext()
        .WriteTo.AzureLogAnalytics(new AzureLogAnalyticsSinkConfiguration
        {
            DataCollectionEndpointUri = new Uri("<data-collection-endpoint>"),
            MaxLogEntries = 10,
            RuleId = "<rule-id>",
            StreamName = "<stream-name>",
            OutputToConsole = true,
            TokenCredential = "optional token credential"
        })
    });

The AzureLogAnalyticsSinkConfiguration type is used to configure the sink.

Property Description
DataCollectionEndpointUri The data collection endpoindt setup in Azure
MaxLogEntries The maximum number of log entries to buffer before flushing to Log Analytics
RuleId The data collection rule id setup in Azure
StreamName The data collection rule stream name (your custom log analytics table
OutputToConsole An optional feature that outputs log output to the console. This is useful when configuring your data collection rule schema and transformation.
TokenCredential An instance of TokenCredential used to authenticate with Azure. This is optional. By default an DefaultAzureCredential is used.
Transform An optional Func<LogEvent, IDictionary<string, object>> to transform a Serilog LogEvent to an IDictionary<string, object> that will be serialized to Json to be sent to Log Analytics. A default implementation is provided if not set. Note: This method should be thread-safe, as it will be called concurrently by Serilog.
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.7 2,991 6/12/2024
1.1.6 98 6/11/2024
1.1.5 81 6/11/2024
1.1.4 96 6/11/2024
1.1.3 1,629 4/18/2024
1.1.2 2,675 4/11/2024
1.0.1 135 4/5/2024

Initial Release