Description
Describe the bug
I'm using the ILambdaLogger interface for structured logging in a Lambda Function. The method "LogError" is called in the code. A method that exists on the ILambdaLogger interface. The method overload in the code takes in the exception, a message, and the arguments referenced in the string. Example from what I do in my code:
´´´
logger.LogError(ex, "HTTP request failed. Status code: {statusCode}",
ex.StatusCode);
´´´
This corresponds to calling:
I tested throwing this exact Exception in my deployed function, and the logging works as expected. A structured log on JSON format is logged:
For unit testing, I use the TestLambdaLogger (that should implement the ILambdaLogger interface). I use XUnit. However, my tests unexpectedly throw on the call to the LogError line in the code above. Parts of the output:
I tested the method overload for LogError that takes in only one string. And that works, it does not throw.
So the problem seems to be that the TestLambdaLogger does not correctly implement the ILambdaLogger interface, as the method overload that works with the deployed function (and local invocation with sam), does not work when running the tests.
Regression Issue
- Select this option if this issue appears to be a regression.
Expected Behavior
This line:
´´´
logger.LogError(ex, "HTTP request failed. Status code: {statusCode}",
ex.StatusCode);
´´´
Should not throw for the TestLambdaLogger. It should just log the information in the console.
Current Behavior
The method fails with a stackoverflow exception.
Reproduction Steps
Run an XUnit test that uses the TestLambdaLogger from the TestLambdaContext.
Use this method from the ILambdaLogger interface in the code that is executed in the test:
void LogError(Exception exception, string message, params object[] args)
{
this.Log(LogLevel.Error.ToString(), exception, message, args);
}
The test will not complete, but give a stackoverflow error.
Possible Solution
No response
Additional Information/Context
Using JetBrains Rider
AWS .NET SDK and/or Package version used
Amazon.Lambda.TestUtilities 2.0.0
Amazon.Lambda.Core 2.5.1
Microsoft.NET.Test.Sdk 17.13.0
xunit 2.9.3
xunit.runner.visualstudio 3.0.2
Targeted .NET Platform
.NET 8.0.407
Operating System and version
macOS Sequoia