Skip to content

Logging properly handles arrays, but not within tuples #63165

Open
@roji

Description

Description

When logging with Microsoft.Extensions.Logging, arrays (or other enumerables) are recognized and emitted properly when they're simple parameters directly referenced by placeholders in the message. However, when the placeholder refers to a value tuple containing an array, ToString is called on the array, yielding the wrong representation.

Serilog properly handles this scenario.

Reproduction Steps

var loggerFactory = LoggerFactory.Create(builder =>
{
    builder.AddSimpleConsole();
    builder.AddProvider(new SerilogLoggerProvider());
});

// Shows 1, 2, 3 - OK
logger.LogInformation("Simple array: {Array}", new[] { 1, 2, 3 });
// Shows (System.Int32[], foo)
logger.LogInformation("Array in tuple: {Tuple}", (Array: new[] { 1, 2, 3 }, SomethingELse: "foo"));

Expected behavior

Something like the following:

Simple array: 1, 2, 3
Array in tuple: ((1, 2, 3), foo)

Serilog outputs:

Simple array: [1, 2, 3]
Array in tuple: [[1, 2, 3], "foo"]

Actual behavior

ToString is called on the array:

Simple array: 1, 2, 3
Array in tuple: (System.Int32[], foo)

Regression?

No response

Known Workarounds

No response

Configuration

.NET 6.0 on Ubuntu Impish

Other information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions