-
In my app I am using the AWS Lambda Powertools logger through the Microsoft ILogger interface as demonstrated in this gist. Microsoft ILogger is defined to support structured logging through the use of message templates, for example: If I use ILogger this way in my lambda handler I get the following error in my logs: {
"cold_start": true,
"function_name": "HelloWorldFunction",
"function_version": null,
"function_memory_size": 0,
"function_arn": "arn:aws:lambda:::function:HelloWorldFunction",
"function_request_id": "da33470f-2731-491a-bb1b-d61bb2a552fa",
"timestamp": "2024-03-14T09:01:07.1236260Z",
"level": "Error",
"service": "service_undefined",
"name": "HelloWorld.Function",
"message": "Powertools internal error",
"exception": {
"type": "System.Reflection.TargetParameterCountException",
"message": "Parameter count mismatch.",
"data": {},
"inner_exception": null,
"help_link": null,
"source": "System.Private.CoreLib",
"h_result": -2147352562,
"stack_trace": " at System.Reflection.MethodBaseInvoker.ThrowTargetParameterCountException()\r\n at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)\r\n at System.Reflection.PropertyInfo.GetValue(Object obj)\r\n at AWS.Lambda.Powertools.Logging.Internal.PowertoolsLogger.GetScopeKeys[TState](TState state)\r\n at AWS.Lambda.Powertools.Logging.Internal.PowertoolsLogger.BeginScope[TState](TState state)\r\n at Microsoft.Extensions.Logging.ScopeLogger.CreateScope[TState](TState state)\r\n at Microsoft.Extensions.Logging.Logger.BeginScope[TState](TState state)\r\n at Microsoft.Extensions.Logging.Logger`1.Microsoft.Extensions.Logging.ILogger.BeginScope[TState](TState state)\r\n at AWS.Lambda.Powertools.Logging.LoggerExtensions.Log[T](ILogger logger, LogLevel logLevel, T extraKeys, EventId eventId, Exception exception, String message, Object[] args)\r\n at AWS.Lambda.Powertools.Logging.LoggerExtensions.Log[T](ILogger logger, LogLevel logLevel, T extraKeys, String message, Object[] args)"
}
} If I don't use a message template everything is fine. However, I want to adhere to Microsoft's recommendations and use message templates whenever that is called for. The At the end of the day, I want to use the AWS Lambda Powertools Logger through a fully implemented Microsoft.Extensions.Logging.ILogger interface. Is this behavior of the logger by design er might this be a bug? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @helgihaf , this issue #496 is being tracked here and is something we want to fix next. |
Beta Was this translation helpful? Give feedback.
Hi @helgihaf , this issue #496 is being tracked here and is something we want to fix next.
My suggestion until we fix this and I know is not a replacement for ILogger message format but one approach is to use the
AppendKey / AppendKeys
to add your Description field orlogger.LogInformation("Hello World! Logging is {Description}.", new[] { "fun" });
Keep an eye on that issue, that we will be tackling next.