@@ -15,6 +15,18 @@ public class CustomizedMaskedLogs
15
15
[ LogMasked ]
16
16
public string ? DefaultMasked { get ; set ; }
17
17
18
+ /// <summary>
19
+ /// 9223372036854775807 results in "***"
20
+ /// </summary>
21
+ [ LogMasked ]
22
+ public long ? DefaultMaskedLong { get ; set ; }
23
+
24
+ /// <summary>
25
+ /// 2147483647 results in "***"
26
+ /// </summary>
27
+ [ LogMasked ]
28
+ public int ? DefaultMaskedInt { get ; set ; }
29
+
18
30
/// <summary>
19
31
/// [123456789,123456789,123456789] results in [***,***,***]
20
32
/// </summary>
@@ -57,6 +69,18 @@ public class CustomizedMaskedLogs
57
69
[ LogMasked ( ShowFirst = 3 ) ]
58
70
public string ? ShowFirstThreeThenDefaultMasked { get ; set ; }
59
71
72
+ /// <summary>
73
+ /// 9223372036854775807 results in "922***807"
74
+ /// </summary>
75
+ [ LogMasked ( ShowFirst = 3 , ShowLast = 3 ) ]
76
+ public long ? ShowFirstAndLastThreeAndDefaultMaskLongInTheMiddle { get ; set ; }
77
+
78
+ /// <summary>
79
+ /// 2147483647 results in "214****647"
80
+ /// </summary>
81
+ [ LogMasked ( ShowFirst = 3 , ShowLast = 3 , PreserveLength = true ) ]
82
+ public int ? ShowFirstAndLastThreeAndDefaultMaskIntInTheMiddlePreservedLength { get ; set ; }
83
+
60
84
/// <summary>
61
85
/// 123456789 results in "123******"
62
86
/// </summary>
@@ -76,11 +100,17 @@ public class CustomizedMaskedLogs
76
100
public string ? ShowLastThreeThenDefaultMaskedPreservedLength { get ; set ; }
77
101
78
102
/// <summary>
79
- /// 123456789 results in "123REMOVED "
103
+ /// 123456789 results in "123_REMOVED_ "
80
104
/// </summary>
81
105
[ LogMasked ( Text = "_REMOVED_" , ShowFirst = 3 ) ]
82
106
public string ? ShowFirstThreeThenCustomMask { get ; set ; }
83
107
108
+ /// <summary>
109
+ /// d3c4a1f2-3b4e-4f5a-9b6c-7d8e9f0a1b2c results in "d3c4a_REMOVED_"
110
+ /// </summary>
111
+ [ LogMasked ( Text = "_REMOVED_" , ShowFirst = 5 ) ]
112
+ public Guid ? ShowFirstFiveThenCustomMaskGuid { get ; set ; }
113
+
84
114
/// <summary>
85
115
/// 123456789 results in "123_REMOVED_"
86
116
/// </summary>
@@ -289,6 +319,25 @@ public void LogMaskedAttribute_Shows_First_NChars_Then_Replaces_All_With_Custom_
289
319
props [ "ShowFirstThreeThenCustomMask" ] . LiteralValue ( ) . ShouldBe ( "123_REMOVED_" ) ;
290
320
}
291
321
322
+ [ Test ]
323
+ public void LogMaskedAttribute_Shows_First_NChars_Then_Replaces_All_With_Custom_Mask_Guid ( )
324
+ {
325
+ // [LogMasked(Text = "_REMOVED_", ShowFirst = 5)]
326
+ // -> "d3c4a_REMOVED_"
327
+ var customized = new CustomizedMaskedLogs
328
+ {
329
+ ShowFirstFiveThenCustomMaskGuid = Guid . Parse ( "d3c4a1f2-3b4e-4f5a-9b6c-7d8e9f0a1b2c" )
330
+ } ;
331
+
332
+ var evt = DelegatingSink . Execute ( customized ) ;
333
+
334
+ var sv = ( StructureValue ) evt . Properties [ "Customized" ] ;
335
+ var props = sv . Properties . ToDictionary ( p => p . Name , p => p . Value ) ;
336
+
337
+ props . ContainsKey ( "ShowFirstFiveThenCustomMaskGuid" ) . ShouldBeTrue ( ) ;
338
+ props [ "ShowFirstFiveThenCustomMaskGuid" ] . LiteralValue ( ) . ShouldBe ( "d3c4a_REMOVED_" ) ;
339
+ }
340
+
292
341
[ Test ]
293
342
public void LogMaskedAttribute_Shows_First_NChars_Then_Replaces_All_With_Custom_Mask_PreservedLength_Ignored ( )
294
343
{
@@ -691,6 +740,84 @@ public void LogMaskedAttribute_Shows_First_NChars_And_Last_NChars_Then_Replaces_
691
740
props [ "ShowFirstAndLastThreeAndCustomMaskInTheMiddlePreservedLengthIgnored" ] . LiteralValue ( ) . ShouldBe ( "123_REMOVED_321" ) ;
692
741
}
693
742
743
+ [ Test ]
744
+ public void LogMaskedAttribute_Replaces_Long_Value_With_DefaultStars_Mask ( )
745
+ {
746
+ // [LogMasked]
747
+ // 9223372036854775807 -> "***"
748
+ var customized = new CustomizedMaskedLogs
749
+ {
750
+ DefaultMaskedLong = long . MaxValue
751
+ } ;
752
+
753
+ var evt = DelegatingSink . Execute ( customized ) ;
754
+
755
+ var sv = ( StructureValue ) evt . Properties [ "Customized" ] ;
756
+ var props = sv . Properties . ToDictionary ( p => p . Name , p => p . Value ) ;
757
+
758
+ props . ContainsKey ( "DefaultMaskedLong" ) . ShouldBeTrue ( ) ;
759
+ props [ "DefaultMaskedLong" ] . LiteralValue ( ) . ShouldBe ( "***" ) ;
760
+ }
761
+
762
+ [ Test ]
763
+ public void LogMaskedAttribute_Shows_First_NChars_And_Last_NChars_Replaces_Long_Value_With_Default_StarMask ( )
764
+ {
765
+ // [LogMasked(ShowFirst = 3, ShowLast = 3)]
766
+ // 9223372036854775807 -> "922***807"
767
+ var customized = new CustomizedMaskedLogs
768
+ {
769
+ ShowFirstAndLastThreeAndDefaultMaskLongInTheMiddle = long . MaxValue
770
+ } ;
771
+
772
+ var evt = DelegatingSink . Execute ( customized ) ;
773
+
774
+ var sv = ( StructureValue ) evt . Properties [ "Customized" ] ;
775
+ var props = sv . Properties . ToDictionary ( p => p . Name , p => p . Value ) ;
776
+
777
+ props . ContainsKey ( "ShowFirstAndLastThreeAndDefaultMaskLongInTheMiddle" ) . ShouldBeTrue ( ) ;
778
+ props [ "ShowFirstAndLastThreeAndDefaultMaskLongInTheMiddle" ] . LiteralValue ( ) . ShouldBe ( "922***807" ) ;
779
+ }
780
+
781
+ [ Test ]
782
+ public void LogMaskedAttribute_Replaces_Int_Value_With_DefaultStars_Mask ( )
783
+ {
784
+ // [LogMasked]
785
+ // 2147483647 -> "***"
786
+ var customized = new CustomizedMaskedLogs
787
+ {
788
+ DefaultMaskedInt = int . MaxValue
789
+ } ;
790
+
791
+ var evt = DelegatingSink . Execute ( customized ) ;
792
+
793
+ var sv = ( StructureValue ) evt . Properties [ "Customized" ] ;
794
+ var props = sv . Properties . ToDictionary ( p => p . Name , p => p . Value ) ;
795
+
796
+ props . ContainsKey ( "DefaultMaskedInt" ) . ShouldBeTrue ( ) ;
797
+ props [ "DefaultMaskedInt" ] . LiteralValue ( ) . ShouldBe ( "***" ) ;
798
+ }
799
+
800
+ [ Test ]
801
+ public void LogMaskedAttribute_Shows_First_NChars_And_Last_NChars_Replaces_Int_Value_With_Default_StarMask_And_PreservedLength ( )
802
+ {
803
+ // [LogMasked(ShowFirst = 3, ShowLast = 3, PreserveLength = true)]
804
+ // 2147483647 -> "214****647"
805
+
806
+ var customized = new CustomizedMaskedLogs
807
+ {
808
+ ShowFirstAndLastThreeAndDefaultMaskIntInTheMiddlePreservedLength = int . MaxValue
809
+ } ;
810
+
811
+ var evt = DelegatingSink . Execute ( customized ) ;
812
+
813
+ var sv = ( StructureValue ) evt . Properties [ "Customized" ] ;
814
+ var props = sv . Properties . ToDictionary ( p => p . Name , p => p . Value ) ;
815
+
816
+ props . ContainsKey ( "ShowFirstAndLastThreeAndDefaultMaskIntInTheMiddlePreservedLength" ) . ShouldBeTrue ( ) ;
817
+ props [ "ShowFirstAndLastThreeAndDefaultMaskIntInTheMiddlePreservedLength" ] . LiteralValue ( ) . ShouldBe ( "214****647" ) ;
818
+ }
819
+
820
+
694
821
[ Test ]
695
822
public void LogMaskedAttribute_Nullify_Bool_Property ( )
696
823
{
0 commit comments