henrique
henrique

Reputation: 31

How to write to multiple CloudWatchLogs log groups using the Lambda function

I have a C# application running on lambda and I need to write to multiple CloudWatch log groups.

Using Nlog and configuring it in code we were able to save to another log group, but in an initial stress test we had a problem with Amazon.CloudWatchLogs.AmazonCloudWatchLogsException: Rate exceeded.

We tried another alternative, configuring Nlog with LambdaLogger.Log (implementation example below), but it did not save to the designated log group, being saved to the Lambda function's log group.

MethodCallTarget loggerTarget = new NLog.Targets.MethodCallTarget("aws", (logEvent, parms) =>
{
    LambdaLogger.Log(logEvent.Message);
});

LoggingConfiguration config = new LoggingConfiguration();

config.AddRuleForAllLevels(loggerTarget);

AWSTarget awsTarget = new AWSTarget()
{
    LogGroup = "aws",
    Region = "sa-east-1"
};
config.AddTarget("aws", awsTarget);

config.LoggingRules.Add(new LoggingRule("aws", NLog.LogLevel.Info, awsTarget));

LogManager.Configuration = config;

Logger logApplication = LogManager.GetCurrentClassLogger();

logApplication.Info(message);

Upvotes: 0

Views: 14

Answers (0)

Related Questions