A Serilog sink that writes events to Kafka.
The Serilog Kafka sink project is a sink (basically a writer) for the Serilog logging framework. Structured log events are written to sinks and each sink is responsible for writing to its own backend, database, store etc. This sink delivers the data to Apache Kafka which is a publish-subscribe messaging system.
Install the Serilog.Sinks.Kafka NuGet package.
Create a logger and start logging messages:
using System;
using Serilog;
public void KafkaConnectionTest()
{
var log = new LoggerConfiguration()
.WriteTo
.Kafka(new KafkaSinkOptions(topic: "test", brokers: new[] { new Uri("http://localhost:9092") }))
.CreateLogger();
log.Information(
"The execution time of this test is {@now}",
new { DateTimeOffset.Now.Hour, DateTimeOffset.Now.Minute });
log.CloseAndFlush();
}
Publishes a message like this:
{
"Timestamp": "2016-05-24T11:50:13.3539190-05:00",
"Level": "Information",
"MessageTemplate": "The execution time of this test is {@now}",
"RenderedMessage": "The execution time of this test is { Hour: 11, Minute: 50 }",
"Properties": {
"now": {
"Hour": 11,
"Minute": 50
}
}
}
- Support durable store-and-forward messaging
- Keep up with the latest Serilog, Kafka, .Net frameworks, etc...