diff --git a/src/Destructurama.Attributed.Tests/MaskedAttributeTests.cs b/src/Destructurama.Attributed.Tests/MaskedAttributeTests.cs index fc53f6f..c761315 100644 --- a/src/Destructurama.Attributed.Tests/MaskedAttributeTests.cs +++ b/src/Destructurama.Attributed.Tests/MaskedAttributeTests.cs @@ -76,11 +76,17 @@ public class CustomizedMaskedLogs public string? ShowLastThreeThenDefaultMaskedPreservedLength { get; set; } /// - /// 123456789 results in "123REMOVED" + /// 123456789 results in "123_REMOVED_" /// [LogMasked(Text = "_REMOVED_", ShowFirst = 3)] public string? ShowFirstThreeThenCustomMask { get; set; } + /// + /// d3c4a1f2-3b4e-4f5a-9b6c-7d8e9f0a1b2c results in "d3c4a_REMOVED_" + /// + [LogMasked(Text = "_REMOVED_", ShowFirst = 5)] + public Guid? ShowFirstThreeThenCustomMaskGuid { get; set; } + /// /// 123456789 results in "123_REMOVED_" /// @@ -289,6 +295,25 @@ public void LogMaskedAttribute_Shows_First_NChars_Then_Replaces_All_With_Custom_ props["ShowFirstThreeThenCustomMask"].LiteralValue().ShouldBe("123_REMOVED_"); } + [Test] + public void LogMaskedAttribute_Shows_First_NChars_Then_Replaces_All_With_Custom_Mask_value_is_Guid() + { + // [LogMasked(Text = "_REMOVED_", ShowFirst = 5)] + // -> "d3c4a_REMOVED_" + var customized = new CustomizedMaskedLogs + { + ShowFirstThreeThenCustomMaskGuid = Guid.Parse("d3c4a1f2-3b4e-4f5a-9b6c-7d8e9f0a1b2c") + }; + + var evt = DelegatingSink.Execute(customized); + + var sv = (StructureValue)evt.Properties["Customized"]; + var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); + + props.ContainsKey("ShowFirstThreeThenCustomMaskGuid").ShouldBeTrue(); + props["ShowFirstThreeThenCustomMaskGuid"].LiteralValue().ShouldBe("d3c4a_REMOVED_"); + } + [Test] public void LogMaskedAttribute_Shows_First_NChars_Then_Replaces_All_With_Custom_Mask_PreservedLength_Ignored() { diff --git a/src/Destructurama.Attributed/Attributed/LogMaskedAttribute.cs b/src/Destructurama.Attributed/Attributed/LogMaskedAttribute.cs index 4f61694..131e596 100644 --- a/src/Destructurama.Attributed/Attributed/LogMaskedAttribute.cs +++ b/src/Destructurama.Attributed/Attributed/LogMaskedAttribute.cs @@ -119,6 +119,7 @@ private LogEventPropertyValue CreateValue(object? value) { IEnumerable strings => new SequenceValue(strings.Select(s => new ScalarValue(FormatMaskedValue(s)))), string s => new ScalarValue(FormatMaskedValue(s)), + Guid g => new ScalarValue(FormatMaskedValue(g.ToString())), _ => ScalarValue.Null }; }