Skip to content

Write structured logging events to a Kafka topic using Serilog in .NET

License

Notifications You must be signed in to change notification settings

akshay123/serilog-sinks-kafka

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serilog.Sinks.Kafka

A Serilog sink that writes events to Kafka.

NuGet Badge

Build status

Build history

Overview

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.

Quick start

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
    }
  }
}

TODO

  • Test with ELK stack
  • Support durable store-and-forward messaging

About

Write structured logging events to a Kafka topic using Serilog in .NET

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 89.4%
  • Batchfile 10.6%