Skip to content

Toluwaloope/MultiSinkLogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MultiSinkLogger

Pluggable logging provider for Microsoft.Extensions.Logging. Route logs to one configured sink (Datadog, Azure Monitor DCE/DCR ingestion, or Seq).

Install

<PackageReference Include="MultiSinkLogger" Version="1.0.0" />

Quick Start

  1. Register in your host builder:
var builder = WebApplication.CreateBuilder(args);

builder.Logging.ClearProviders();
builder.Logging.AddConsole();

// Bind from configuration section
builder.Logging.AddMultiSinkLogger(builder.Configuration.GetSection("Logging:MultiSinkLogger"));

var app = builder.Build();
  1. Configure one sink in appsettings.json:
{
  "Logging": {
    "LogLevel": {
      "Default": "Information"
    },
    "MultiSinkLogger": {
      "MinimumLevel": "Information",
      "Datadog": {
        "Enabled": true,
        "ApiKey": "<DD_API_KEY>",
        "BaseUrl": "https://http-intake.logs.datadoghq.com",
        "Service": "my-app",
        "Source": "csharp",
        "Host": "my-host"
      },
      "Seq": {
        "Enabled": false,
        "ServerUrl": "http://localhost:5341",
        "ApiKey": ""
      },
      "AzureDce": {
        "Enabled": false,
        // Option A: Provide full ingestion URI
        "IngestionUri": "https://<dce>.<region>-ingest.monitor.azure.com/dataCollectionRules/<immutableDcrId>/streams/Custom-MyAppLogs?api-version=2023-01-01",
        // Option B: Construct from components using immutable DCR ID
        "DceEndpointUrl": "https://<dce>.<region>-ingest.monitor.azure.com",
        "DcrImmutableId": "<immutableDcrId>",
        "StreamName": "Custom-MyAppLogs",
        "ApiVersion": "2023-01-01",
        // Authentication options
        "UseManagedIdentity": true,
        // Or specify Azure AD app credentials
        "TenantId": "<tenant-guid>",
        "ClientId": "<app-client-id>",
        "ClientSecret": "<app-client-secret>"
      }
    }
  }
}
  1. Log as usual using ILogger<T>.

Supported Sinks

  • Datadog: Uses v2 logs intake (/api/v2/logs) with DD-API-KEY.
  • Seq: Sends CLEF lines to /ingest/clef (optional X-Seq-ApiKey).
  • Azure DCE/DCR: Posts array of records to the ingestion URI. You can provide the full URI or construct it via DceEndpointUrl + DcrImmutableId + StreamName. Auth via DefaultAzureCredential (managed identity), Azure AD app credentials (TenantId, ClientId, ClientSecret), or a static bearer token.

Notes

  • MultiSinkLogger supports only one sink at a time. If more than one sink is enabled, startup will throw a configuration error.
  • MinimumLevel filters what reaches the sinks; LoggingBuilder filters still apply.
  • Keep API keys and secrets in secure configuration sources.

Examples and How-To

For practical scenarios and complete examples, see docs/examples-and-usage.md.

Pack

dotnet pack -c Release

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages