This Serilog Sink allows to log to AWS CloudWatch. It supports .NET Framework 4.6 and .NET Core.
// name of the log group
var logGroupName = "myLogGroup/" + env.EnvironmentName;
// customer renderer (optional, defaults to a simple rendered message of Serilog's LogEvent
var renderer = new MyCustomRenderer();
// options for the sink, specifying the log group name
CloudWatchSinkOptions options = new CloudWatchSinkOptions {LogGroupName = logGroupName, LogEventRenderer = MyCustomRenderer};
// setup AWS CloudWatch client
AWSCredentials credentials = new BasicAWSCredentials(myAwsAccessKey, myAwsSecretKey);
IAmazonCloudWatchLogs client = new AmazonCloudWatchLogsClient(credentials, myAwsRegion);
// Attach the sink to the logger configuration
Log.Logger = new LoggerConfiguration().MinimumLevel.Information()
.WriteTo.AmazonCloudWatch(options, client)
.CreateLogger();
Errors related to the setup of the Sink (for example, invalid AWS credentials), or problems during sending the data are logged to Serilog's SelfLog.
Short version, enable it with something like the following command:
Serilog.Debugging.SelfLog.Enable(Console.Error);
We value your input as part of direct feedback to us, by filing issues, or preferably by directly contributing improvements:
- Fork this repository
- Create a branch
- Contribute
- Pull request