Lurgle.Logging adds AWS Cloudwatch support
It's been a while since I've added functionality to Lurgle libraries, but I played around with adding AWS Cloudwatch support to Lurgle.Logging. This affords further opportunities to use Lurgle.Logging as a common logging library with all its 'baked in' benefits. To do this, I leveraged the 'official' AWS.Logger.Serilog sink. Puzzlingly, it looks like this might not support use via proxy servers, but otherwise I'm quite happy with it.
As with all of the logging targets, there are two ways to readily configure this;
1. Using app.config values to enable the Aws sink and then configuring the relevant values. As a rule, LogAwsLogGroup and LogAwsRegion are mandatory.
<add key="LogType" value="Console,File,Aws" />
<add key="LogLevelAws" value="Verbose"/>
<!--== AWS Cloudwatch configuration-->
<add key="LogAwsProfile" value = "" />
<add key="LogAwsProfileLocation" value=""/>
<!-- Only use AWS Key and Secret for testing - best practice to use the AWS Profile -->
<add key="LogAwsKey" value="" />
<add key="LogAwsSecret" value="" />
<!-- Required to direct logs to the correct log group and region -->
<add key="LogAwsLogGroup" value="Blah" />
<add key="LogAwsRegion" value="us-east-1" />
<add key="LogAwsCreateLogGroup" value="true" />
<!-- Optional stream prefix and suffix-->
<add key="LogAwsStreamPrefix" value=""/>
<add key="LogAwsStreamSuffix" value=""/>
2. Using a constructor
Logging.SetConfig(new LoggingConfig(Logging.Config, logAwsLogGroup: "Blah", logAwsRegion: "us-east-1", logAwsCreateLogGroup: true));
As a rule of thumb, LogAwsLogGroup and LogAwsRegion should be treated as mandatory.
You should use the LogAwsProfile method of providing credentials per Configure AWS credentials - AWS SDK for .NET (amazon.com), rather than the LogAwsKey/LogAwsSecret keys. These configuration keys exist only for testing purposes - don't use them in production.
For output, I diverged from using the compact JSON format that Serilog defaults to, and used a rendered JSON format that results in output like this:
This preserves the structured properties that are output by Lurgle.Logging, but accomodates the lack of message template coverage in Cloudwatch.
This results in Cloudwatch's ability to return the properties in Logs Insights, for example:
Which should then translate through any functionality that can leverage the properties.
This is a fairly straightforward addition that seems to work quite happily. We can iterate further on this if it proves necessary - but I'm certainly happy to have this up and running.
This is available on Nuget now!
Comments