How to Configure LogMonitor and CloudWatch Logs for ECS Windows Tasks
18 Jan 2025Windows applications often use different logging mechanisms than their Linux counterparts. Instead of relying on STDOUT
, Windows apps typically utilize Windows-specific logging methods, such as ETW
, the Event Log
, or custom log files
like IIS logs
. If you’re running a Windows container in an ECS cluster and want to capture Windows and IIS logs in CloudWatch
, you’ll need to implement Log Monitor
instrumentation. This setup redirects IIS and system logs to STDOUT
, allowing the awslogs driver to automatically capture and forward them to CloudWatch
Logs.
Setting Up Log Monitor and CloudWatch for IIS Logs
Follow these steps to configure Log Monitor and send IIS logs to CloudWatch:
-
Identify the Log Providers.
Determine the providers to include in the configuration file using:
logman query providers | findstr "<GUID or Provider Name>"
For IIS, you can use:
IIS: WWW Server
with GUID3A2A4E84-4C21-4981-AE10-3FDA0D9B0F83
-
Create the LogMonitorConfig.json file.
This file specifies which logs to capture. Below is an example configuration capturing system logs, application logs, and IIS logs:
{ "LogConfig": { "sources": [ { "type": "EventLog", "startAtOldestRecord": true, "eventFormatMultiLine": false, "channels": [ { "name": "system", "level": "Information" }, { "name": "application", "level": "Error" } ] }, { "type": "File", "directory": "c:\\inetpub\\logs", "filter": "*.log", "includeSubdirectories": true, "includeFileNames": false }, { "type": "ETW", "eventFormatMultiLine": false, "providers": [ { "providerName": "IIS: WWW Server", "providerGuid": "3A2A4E84-4C21-4981-AE10-3FDA0D9B0F83", "level": "Information" }, { "providerName": "Microsoft-Windows-IIS-Logging", "providerGuid": "7E8AD27F-B271-4EA2-A783-A47BDE29143B", "level": "Information" } ] } ] } }
-
Download Log Monitor
Download LogMonitor.exe from the GitHub repository binaries.
-
Update Your Dockerfile
Integrate Log Monitor into your Docker container. Refer to the usage guide here.
Example Dockerfile:
FROM mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2022 WORKDIR /LogMonitor COPY LogMonitorConfig.json LogMonitor.exe ./ ENTRYPOINT ["C:\\LogMonitor\\LogMonitor.exe", "C:\\ServiceMonitor.exe", "w3svc"]
-
Configure CloudWatch Logs in the Task Definition
Enable CloudWatch logs and set up the log driver in your ECS task definition:
Task definition example:
"logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group": "/ecs/iis-logs", "awslogs-create-group": "true", "awslogs-region": "us-east-1", "awslogs-stream-prefix": "ecs" } }
-
Rebuild and Deploy
- Rebuild the container image and push it to your ECR repository.
- Update the ECS task definition to use the new image and deploy it to the cluster.
Viewing Logs in CloudWatch
- Open the
Amazon ECS console
. - Navigate to the cluster containing the task.
- Select the
Tasks
tab and choose a task to view. - Expand the container details by clicking the arrow next to its name.
- In the
Log Configuration section
, selectView logs in CloudWatch
to access the log stream.
Example Outputs
-
ETW and Log Entries:
-
Application Exceptions:
Your donations are appreciated. Thank you!