![]() |
VOOZH | about |
dotnet add package Serilog.Sinks.ConfluentKafka --version 0.1.4
NuGet\Install-Package Serilog.Sinks.ConfluentKafka -Version 0.1.4
<PackageReference Include="Serilog.Sinks.ConfluentKafka" Version="0.1.4" />
<PackageVersion Include="Serilog.Sinks.ConfluentKafka" Version="0.1.4" />Directory.Packages.props
<PackageReference Include="Serilog.Sinks.ConfluentKafka" />Project file
paket add Serilog.Sinks.ConfluentKafka --version 0.1.4
#r "nuget: Serilog.Sinks.ConfluentKafka, 0.1.4"
#:package Serilog.Sinks.ConfluentKafka@0.1.4
#addin nuget:?package=Serilog.Sinks.ConfluentKafka&version=0.1.4Install as a Cake Addin
#tool nuget:?package=Serilog.Sinks.ConfluentKafka&version=0.1.4Install as a Cake Tool
A Serilog sink that writes events to Kafka Endpoints (Including Azure Event Hubs).
This sink works with the following packages
Log.Logger = new LoggerConfiguration()
.WriteTo.Kafka()
.CreateLogger();
$ConnectionString./cacert.pem as this package includes the Azure carcert.pem file which is copied into your binary output directory.ITextFormatter you can specify to format log entries. Defaults to the standard JsonFormatter with renderMessage set to true.{
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{
"Name": "Kafka",
"Args": {
"batchSizeLimit": "50",
"period": "5",
"bootstrapServers": "localhost:9092",
"topic": "logs"
}
}
]
}
}
topicDecider and a custom formatterLog.Logger = new LoggerConfiguration()
.WriteTo.Kafka(GetTopicName, "localhost:9092",
formatter: new CustomElasticsearchFormatter("LogEntry"));
.CreateLogger();
The code above specifies GetTopicName as the topicDecider. Here is a sample implementation:
private static string GetTopicName(LogEvent logEntry)
{
var logInfo = logEntry.Properties["LogEntry"] as StructureValue;
var lookup = logInfo?.Properties.FirstOrDefault(a => a.Name == "some_property_name");
return (string.Equals(lookup, "valueForTopicA"))
? "topicA"
: "topicB";
}
The above code also references a CustomElasticSearchFormatter that uses the whole LogEntry as the input to the formatter. This is a custom formatter that inherits from ElasticsearchJsonFormatter in the Serilog.Sinks.Elasticsearch NuGet package, but can be any ITextFormatter that you want to use when sending the log entry to Kafka. Note that if you omit the formatter param (which is fine), the standard JsonFormatter will be used (with the renderMessage parameter set to true).
You will need to ensure you have a copy of the Azure CA Certificates and define the location of this cert in the sslCaLocation.
You can download a copy of the Azure CA Certificate .
Place this in you projects root directory and ensure it is copied to the build output in your csproj.
<ItemGroup>
<None Include="cacert.pem">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
Log.Logger = new LoggerConfiguration()
.WriteTo.Kafka(
batchSizeLimit: 50,
period: 5,
bootstrapServers: "my-event-hub-instance.servicebus.windows.net:9093",
saslUsername: "$ConnectionString",
saslPassword: "my-event-hub-instance-connection-string",
topic: "logs",
sslCaLocation: "./cacert.pem",
saslMechanism: SaslMechanism.Plain,
securityProtocol: SecurityProtocol.SaslSsl)
.CreateLogger();
{
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{
"Name": "Kafka",
"Args": {
"batchSizeLimit": "50",
"period": "5",
"bootstrapServers": "my-event-hub-instance.servicebus.windows.net:9093",
"saslUsername": "$ConnectionString",
"saslPassword": "my-event-hub-instance-connection-string",
"topic": "logs",
"sslCaLocation": "./cacert.pem",
"saslMechanism": "Plain",
"securityProtocol": "SaslSsl"
}
}
]
}
}
You can also specify ProducerConfig configuration using EnvironmentVariables.
These settings can be specified as the following EnvironmentVariables...
SERILOG__KAFKA__ProducerConfigPropertyName
or
SERILOG__KAFKA__PRODUCER_CONFIG_PROPERTY_NAME.
SERILOG__KAFKA__ is first stripped from the Environment Variable Name and the remaining name is lowered and single _ is replaced with string.Empty.
The ProducerConfig is first loaded from any specified Environment Variables. Then any of the configuration passed into the KafkaSink constructor will override the Environment Variables.
This is to ensure backwards compatability at the moment but passing this configuration into the KafkaSink constructor will be removed in the future.
You can check what properties are supported at the following github https://github.com/confluentinc/confluent-kafka-dotnet/blob/6128bdf65fa79fbb14210d73970fbd4f7940d4b7/src/Confluent.Kafka/Config_gen.cs#L830
If you are running against an Azure EventHub, the following configuration is recommended.
https://github.com/Azure/azure-event-hubs-for-kafka/blob/master/CONFIGURATION.md
These EnvironmentVariables can be set...
SERILOG__KAFKA__SocketKeepaliveEnable=true
SERILOG__KAFKA__MetadataMaxAgeMs=180000
SERILOG__KAFKA__RequestTimeoutMs=30000
SERILOG__KAFKA__Partitioner=ConsistentRandom
SERILOG__KAFKA__EnableIdempotence=false
SERILOG__KAFKA__CompressionType=None
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Serilog.Sinks.ConfluentKafka:
| Package | Downloads |
|---|---|
|
EventBankingCo.Core.Logging
Package Description |
|
|
IscB2b.Core.Infrastructure
B2b Core Infrastructure |
|
|
SU2.Infrastructure.Observability
Clean Architecture template — Infrastructure.Observability sub-package: Serilog logging (Kafka/OTLP/EventLog sinks) + OpenTelemetry traces/metrics/logs (instrumentation, resource detectors, OTLP + Prometheus exporters) + OTLP exporter health check + sensitive-data redactor. Numeronym `C15e` = CleanArchitecture. Generation 2026 series. |
|
|
SU2.Infrastructure
Clean Architecture template — Infrastructure layer (EF Core interceptors for audit/event-dispatch/soft-delete/no-lock, EfRepository, AppDbContext base, Dapper IDbSession, Redis + HybridCache + DistributedLock, Kafka producer/consumer base, MongoDB.EFCore wiring, Hangfire adapters, PhenX bulk-insert for SQL Server/PostgreSQL/MySQL/SQLite/Oracle, Serilog + OpenTelemetry wiring, fake implementations of UseCases interfaces). Numeronym `C15e` = CleanArchitecture. Generation 2026 series. |
|
|
SU2.Web
Clean Architecture template — Web library layer (FastEndpoints BaseEndpoint base classes, InternalAuthorize, middleware: GlobalExceptionHandler/RequestCorrelation/Timeout, JsonErrorMessageResolver, CORS + Compression setup helpers, ForwardCurrentUserHandler, CurrentUser/CurrentUserOptions services, FastEndpointsErrorBuilder, ServiceConfigs + OptionConfigs + MediatorConfig + MiddlewareConfig extension methods). Numeronym `C15e` = CleanArchitecture. Generation 2026 series. |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 0.1.4 | 129,989 | 11/26/2024 | |
| 0.1.3 | 290 | 11/26/2024 | |
| 0.1.2 | 111,559 | 4/24/2024 | |
| 0.1.1 | 56,972 | 1/6/2023 | |
| 0.1.0 | 712 | 7/22/2022 | 0.1.0 is deprecated because it has critical bugs. |
| 0.0.7 | 467 | 1/6/2023 | |
| 0.0.6 | 760 | 7/22/2022 | |
| 0.0.5 | 661 | 6/22/2022 | |
| 0.0.4 | 578 | 6/22/2022 | |
| 0.0.3 | 596 | 6/22/2022 | |
| 0.0.2 | 601 | 6/22/2022 | |
| 0.0.1 | 766 | 6/22/2022 | 0.0.1 is deprecated because it is no longer maintained and has critical bugs. |