Skip to content

wcrooy/serilog-sinks-amazonkinesis

 
 

Repository files navigation

Serilog.Sinks.AmazonKinesis Build status

A Serilog sink that writes events as documents to Amazon Kinesis.

Getting started

To get started install the Serilog.Sinks.AmazonKinesis package from Visual Studio's NuGet console:

PM> Install-Package Serilog.Sinks.AmazonKinesis

Point the logger to Kinesis:

const string streamName = "firehose";
const int shardCount = 2;

SelfLog.Out = Console.Out;

var client = AWSClientFactory.CreateAmazonKinesisClient();
            
var streamOk = KinesisApi.CreateAndWaitForStreamToBecomeAvailable(
    kinesisClient: client, 
    streamName: streamName, 
    shardCount: shardCount
);
            
var loggerConfig = new LoggerConfiguration()
    .WriteTo.ColoredConsole()
    .MinimumLevel.Debug();

if (streamOk)
{
    loggerConfig.WriteTo.AmazonKinesis(
        kinesisClient: client,
        streamName: streamName,
        period: TimeSpan.FromSeconds(2),
        bufferLogShippingInterval: TimeSpan.FromSeconds(5),
        bufferBaseFilename: "./logs/kinesis-buffer"
    );
}

Log.Logger = loggerConfig.CreateLogger();
    

And use the Serilog logging methods to associate named properties with log events:

Log.Error("Failed to log on user {ContactId}", contactId);

About

A Serilog sink that logs to Amazon Kinesis

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 98.6%
  • PowerShell 1.4%