Amazon CloudWatch

How to Log with CloudWatch Logs, ASP.NET and Log4Net

The Apache Software Foundation’s Logging Services project aims to provide a group of cross-language logging services that allows producers of software to debug and audit their software. The project includes Log4j, Log4j Audit, Log4j Kotlin, Log4j Scala, Log4cxx, Log4Net and Log4PHP.

We’ll spend our time in this tutorial with Log4Net, the .NET port of Log4j. We’ll build a very basic API application to demonstrate how .NET apps can use Log4Net to output logs to Amazon CloudWatch Logs.

Logging to Amazon CloudWatch Logs with ASP.NET

Photo by Sebastian Pociecha on Unsplash

Observability is the procedure of analyzing a software system by collecting and analyzing its data. Observability allows you to understand what is happening inside the system in order to debug software issues, analyze a system’s performance, identify usage patterns, triage security incidents, et al.

Logging is an important aspect of observability as logging is a crucial mechanism in capturing the data that needs to be analyzed. In this series, we’ll go over logging to Amazon CloudWatch Logs using three popular .NET logging platforms – Serilog, Log4Net and NLog.

How to Log with ASP.NET, NLog and Amazon CloudWatch Logs

NLog is known for being a free, flexible logging solution which supports structured, as well as traditional logging within the .NET ecosystem. NLog has logging targets for the console, for files, and for databases. However, in this tutorial, we’ll use ASP.NET along with NLog to store logs in CloudWatch Logs.

Photo by Robert Larsson on Unsplash

The Solution

In this tutorial, we will build a basic ASP.NET API, with the goal of logging to Amazon CloudWatch Logs using NLog.

How to Log to CloudWatch Logs using ASP.NET and Serilog

Serilog is well known in the .NET community as a simple, versatile provider for structured logging. Combine Serilog with CloudWatch Logs which enables the centralization of all your logs within a highly scalable service and you have a very powerful solution. In this article, we’ll integrate ASP.NET, Serilog and CloudWatch Logs to form a powerful debugging, troubleshooting and monitoring solution.

Photo by Mildly Useful on Unsplash

The Solution

In this tutorial, we will provide a simple example where we log to Amazon CloudWatch Logs using ASP.NET and Serilog.