Pluggable logging provider for Microsoft.Extensions.Logging. Route logs to one configured sink (Datadog, Azure Monitor DCE/DCR ingestion, or Seq).
<PackageReference Include="MultiSinkLogger" Version="1.0.0" />
- 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();- 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>"
}
}
}
}- Log as usual using
ILogger<T>.
- Datadog: Uses v2 logs intake (
/api/v2/logs) withDD-API-KEY. - Seq: Sends CLEF lines to
/ingest/clef(optionalX-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 viaDefaultAzureCredential(managed identity), Azure AD app credentials (TenantId,ClientId,ClientSecret), or a static bearer token.
- MultiSinkLogger supports only one sink at a time. If more than one sink is enabled, startup will throw a configuration error.
MinimumLevelfilters what reaches the sinks; LoggingBuilder filters still apply.- Keep API keys and secrets in secure configuration sources.
For practical scenarios and complete examples, see docs/examples-and-usage.md.
dotnet pack -c Release