Tutorial: Using Amazon Logging Frameworks with Amazon Lambda to Create Application Logs - Amazon Toolkit with Amazon Q
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Tutorial: Using Amazon Logging Frameworks with Amazon Lambda to Create Application Logs

You can use Amazon CloudWatch Logs to monitor, store, and access your application’s logs. To get log data into CloudWatch Logs, use an Amazon SDK or install the CloudWatch Logs agent to monitor certain log folders. CloudWatch Logs is integrated with several popular .NET logging frameworks, simplifying work flows.

To get started working with CloudWatch Logs and .NET logging frameworks, add the appropriate NuGet package and CloudWatch Logs output source to your application, then use your logging library as you normally would. This enables your application to log messages with your .NET framework, sending them to CloudWatch Logs, displaying your application’s log messages in the CloudWatch Logs console. You can also set up metrics and alarms from the CloudWatch Logs console, based on your application’s log messages.

Supported .NET logging frameworks include:

The following is an example of an NLog.config file that enables both CloudWatch Logs and the console as output for log messages by adding the AWS.Logger.NLog NuGet package, and Amazon target into NLog.config.

<?xml version="1.0" encoding="utf-8" ?> <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true"> <targets> <target name="aws" type="AWSTarget" logGroup="NLog.ConfigExample" region="us-east-1"/> <target name="logfile" xsi:type="Console" layout="${callsite} ${message}" /> </targets> <rules> <logger name="*" minlevel="Info" writeTo="logfile,aws" /> </rules> </nlog>

The logging plugins are all built on top of the Amazon SDK for .NET and authenticate your Amazon credentials in a process similar to the SDK. The following example details permissions required by the logging plugin credentials to access CloudWatch Logs:


The Amazon .NET logging plugins are an open source project. For additional information, samples, and instructions, see the samples and instructions topics in the Amazon Logging .NET GitHub repository.

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents", "logs:DescribeLogGroups" ], "Resource": [ "arn:aws:logs:*:*:*" ] } ] }