generated from amazon-archives/__template_Apache-2.0
- Notifications
You must be signed in to change notification settings - Fork 33
Closed
Labels
area/loggingCore logging utilityCore logging utilitybugUnexpected, reproducible and unintended software behaviourUnexpected, reproducible and unintended software behaviour
Description
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
Labels
area/loggingCore logging utilityCore logging utilitybugUnexpected, reproducible and unintended software behaviourUnexpected, reproducible and unintended software behaviour
Type
Projects
Status
✅ Done