Reputation: 265
I have an app written in .NET Core 3.1, dockerized, and deployed to AWS ECS. My Task Definition is configured to send logs to CloudWatch.
No matter what I do, I can't seem to configure logging within my app to send custom logs.
Program.cs
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureLogging(o =>
{
o.AddAWSProvider();
o.SetMinimumLevel(LogLevel.Debug);
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
MyService.cs
[ServiceContract]
public class HealthCheckService
{
private readonly ILogger<HealthCheckService> _logger;
public HealthCheckService(ILogger<HealthCheckService> logger)
{
_logger = logger;
}
[OperationContract]
public string HealthCheck(string input)
{
_logger.LogInformation("test from health check");
return input;
}
}
The service endpoint works. I can call it and get back a good response. But in CloudWatch I don't see anything but the same few basic logs.
Shouldn't logging be stupidly simple? Perhaps it is, and I should just feel very poorly about myself...
Upvotes: 0
Views: 1651
Reputation: 1161
I am testing with CloudWatchFullAccess policy
Check if you are looking in the correct region. My configuration is like this(https://github.com/aws/aws-logging-dotnet#aspnet-core-logging)
"Logging": {
"IncludeCategory": true,
"IncludeEventId": false,
"IncludeException": true,
"IncludeLogLevel": true,
"IncludeNewline": true,
"IncludeScopes": false,
"LogGroup": "AspNetCore.WebSample",
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
},
"Region": "eu-central-1"
}
My CloudWatch logs are in Europe (Frankfurt) eu-central-1
Nothing is as easy as it should be, so don't worry if things don't work out the first time.
Upvotes: 2