Tutorials AWS Mastery for .NET Architects
CloudWatch: Metrics, Logs, and Alarms for C# apps
On this page
Observability Foundations
AWS CloudWatch is the eye of your AWS account. It collects monitoring and operational data in the form of logs, metrics, and events.
1. Metrics and Alarms
Metrics are time-series data (e.g., CPU %, Error Count). **Architect Hint:** Don't just watch CPU. Set up **CloudWatch Alarms** on business metrics, like 'Number of Failed Payments > 5 in 1 minute'. This allows you to catch business logic errors before they affect your bottom line.
2. CloudWatch Logs Insights
Forget scrolling through megabytes of text logs. **Logs Insights** allows you to run SQL-like queries on your logs. "fields @timestamp, @message | filter @message like /Error/ | sort @timestamp desc". It's incredibly fast and powerful for production troubleshooting.
3. Architect Insight
Q: "How do I save money on CloudWatch Logs?"
Architect Answer: "Set a **Retention Policy**. By default, CloudWatch keeps logs forever, which can become expensive. Set your Dev/Test logs to expire after 7 days and Prod logs to archive to S3 after 30-90 days. Also, avoid 'Log Spam' by using the appropriate log levels (Warning/Error) in production."