Skip to content

Conversation

sungam3r
Copy link
Contributor

fixes #2019

Copy link
Member

@nblumhardt nblumhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sending this. Keen to look at the IScalarConversionPolicy route, since it would keep some complexity out of the (already a bit complex) PropertyValueConverter class.

@@ -21,6 +21,7 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="all" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="Shouldly" Version="4.1.0" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keen not to introduce a new inconsistent set of assertions into this project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

evt.Properties.Count.ShouldBe(1);
var arr = evt.Properties["Value"].ShouldBeOfType<SequenceValue>();
arr.Elements.Count.ShouldBe(6);
arr.LiteralValue().ShouldBe("[a,b,c,d,e,f]");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would expect [[a,b],[c,d],[e,f]] here I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it intentionally since any array is just a sequence in terms of serilog regardless dimensions. Nevertheless I can change implementation to emit sequence of sequences if you like.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -214,6 +214,29 @@ bool TryConvertEnumerable(object value, Type type, Destructuring destructuring,
{
result = SequenceValue.Empty;
}
else if (list is Array a && a.Rank > 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this could be plugged in as an IScalarConversionPolicy instead? Since those are checked before this code is reached, we could avoid the extra condition here. We do this already to specialize conversion of byte arrays.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IScalarConversionPolicy has no access to

  1. _depthLimiter (can be solved)
  2. destructuring boolean argument

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, we should not use IScalarConversionPolicy here, because the determining factor whether or not using IScalarConversionPolicy is the type of object inside the array, regardless of the dimensions of the array.

}
else
{
throw new NotSupportedException("Serilog does not support multi-dimensional arrays with Rank > 3.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is not a usage error but just a limitation, perhaps we should just use

result null;
return false;

here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this is a good candidate to get into 4.0; shall I make these final tweaks and merge this, @sungam3r?

Copy link
Contributor

@WAcry WAcry Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the work on supporting multi-dimensional arrays. ❤️ I hope this feature can be merged soon.

I believe there’s no reason not to support higher-dimensional arrays. Based on this branch, I have further improved the implementation to allow support for arrays with more dimensions: #2132

cc:
@sungam3r
@nblumhardt

@nblumhardt
Copy link
Member

Committed via #2312

@nblumhardt nblumhardt closed this Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logging multidimensional 2d array fails silently
3 participants