Skip to content

Bug: AddPowertoolsLogger does not add logger to DI Container #937

@j-d-ha

Description

@j-d-ha

Expected Behaviour

The API documentation mentions that the powertools logger can be registered using the following code:

builder.Logging.AddPowertoolsLogger(options => { options.MinimumLogLevel = LogLevel.Information; options.LoggerOutputCase = LoggerOutputCase.PascalCase; options.IncludeLogLevel = true; });

I would expect this to register the powertools logger in the DI container for use later.

Current Behaviour

If I use the above code and then try and pull an instance of ILogger out of the DI container, I get the following error:

Unhandled exception. System.InvalidOperationException: No service for type 'Microsoft.Extensions.Logging.ILogger' has been registered. 

Code snippet

var builder = Host.CreateApplicationBuilder(); builder.Services.AddSingleton<Function>(); builder.Services.AddSingleton<Service>(); builder.Logging.AddPowertoolsLogger(config => { config.Service = "top-level-function-demo"; config.JsonOptions = new JsonSerializerOptions() { WriteIndented = true }; }); var host = builder.Build(); var logger = host.Services.GetRequiredService<ILogger>(); logger.LogInformation("Starting lambda");

Possible Solution

No response

Steps to Reproduce

  • Add the above code to an empty project.
  • Install dependencies.
  • Run the project, and an error will be encountered.

Powertools for AWS Lambda (.NET) version

AWS.Lambda.Powertools.Logging 2.0.0

AWS Lambda function runtime

dotnet8

Debugging logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/loggingCore logging utilitybugUnexpected, reproducible and unintended software behaviour

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions