Aws-lambda-dotnet: Logging settings not working for Serverless API Blueprint

Created on 18 Feb 2019  ·  7Comments  ·  Source: aws/aws-lambda-dotnet

Steps to reproduce:

  1. Create a new Serverless application using ASP.NET Core Web API from Blueprint
  2. Amend ValuesController to have the following code:
    private readonly ILogger<ValuesController> _logger;

    public ValuesController(ILogger<ValuesController> logger)
    {
        _logger = logger;
    }

    // GET api/values
    [HttpGet]
    public IEnumerable<string> Get()
    {
        _logger.LogDebug("This is a DEBUG comment");
        return new string[] { "value1", "value2" };
    }
  1. Run code
  2. Using postman, hit the ValuesController Get.

I can see 2 possible solutions here:
a) Amend appsetings.json to Logging section instead of Lambda.Logging
b) Amend this file aws-lambda-dotnet/blob/master/Libraries/src/Amazon.Lambda.AspNetCoreServer/AbstractAspNetCoreFunction.cs Line 179 to not include the Section "Logging"

bug investigating

All 7 comments

I'm going to start working on reproducing this now. What is the exception/problem you are seeing?

I was expecting "This is a DEBUG comment" to appears in debug logs (console app and CloudWatch). They are not appearing neither one.

Hi @matheusmaximo, I'm not sure why Debug logs don't work, but it could be related to https://github.com/aws/aws-logging-dotnet/issues/52. For you, at least you are already using the correct Amazon.Lambda.Logging.AspNetCore logging library if you are using the Serverless API Blueprint. I don't think the solutions you recommended are appropriate. If you try creating some logs with other log levels, which should work, you will see that adjusting the log levels in the appsettings.json will correctly filter out low log levels.

I'll talk with @normj to find out more about the complications with Debug logs.

Looks like we have a bug in the Amazon.Lambda.AspNetCoreServer that is not pulling the log levels into the ILoggingBuilder. I'll investigate why that is happening.

You can change the minimum in code by editing the class that extends from APIGatewayProxyFunction which is usually LambdaEntryPoint

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;

namespace LambdaLoggingDebugTest
{
    public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
    {
        protected override void Init(IWebHostBuilder builder)
        {
            builder
                .UseStartup<Startup>()
                .ConfigureLogging((hostingContext, logging) =>
                {
                    logging.SetMinimumLevel(LogLevel.Trace);
                });
        }
    }
}

I found the problem in the library causing the logging settings to not be correctly read from appsettings.json https://github.com/aws/aws-lambda-dotnet/commit/0d3cdb39d3c72d45956ebc2f2e6612c3fde277cd

I'll get the fix out soon.

I just released version 3.0.2 of Amazon.Lambda.AspNetCoreServer which fixes the bug with logging not being read from config.

I confirm that this fixed the problem. Thank you all!

Was this page helpful?
0 / 5 - 0 ratings