A Serilog sink that writes events as documents to Amazon Kinesis.
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);