Skip to content

Commit 060146b

Browse files
Update README with configuration options for masking operators
1 parent 9c8ed17 commit 060146b

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

README.md

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,44 @@ The effect is that the log message will be rendered as:
9595

9696
See the [Serilog.Enrichers.Sensitive.Demo](src/Serilog.Enrichers.Sensitive.Demo/Program.cs) app for a code example of the above.
9797

98-
## Using a custom mask value
98+
### Configuring masking operators to use
99+
100+
By default the enricher uses the following masking operators:
101+
102+
- EmailAddressMaskingOperator
103+
- IbanMaskingOperator
104+
- CreditCardMaskingOperator
105+
106+
It's good practice to only configure the masking operators that are applicable for your application. For example:
107+
108+
```csharp
109+
new LoggerConfiguration()
110+
.Enrich
111+
.WithSensitiveDataMasking(
112+
options =>
113+
{
114+
options.MaskingOperators = new List<IMaskingOperator>
115+
{
116+
new EmailAddressMaskingOperator(),
117+
new IbanMaskingOperator()
118+
// etc etc
119+
};
120+
});
121+
```csharp
122+
123+
It is also possible to not use any masking operators but instead mask based on property names. In that case you can configure the enricher to not use any masking operators at all:
124+
125+
```csharp
126+
new LoggerConfiguration()
127+
.Enrich
128+
.WithSensitiveDataMasking(
129+
options =>
130+
{
131+
options.MaskingOperators.Clear();
132+
});
133+
```csharp
134+
135+
### Using a custom mask value
99136

100137
In case the default mask value `***MASKED***` is not what you want, you can supply your own mask value:
101138

@@ -112,7 +149,7 @@ A example rendered message would then look like:
112149

113150
You can specify any mask string as long as it's non-null or an empty string.
114151

115-
## Always mask a property
152+
### Always mask a property
116153

117154
It may be that you always want to mask the value of a property regardless of whether it matches a pattern for any of the masking operators. In that case you can specify that the property is always masked:
118155

@@ -133,7 +170,7 @@ logger.Information("This is a sensitive {Email}", "this doesn't match the regex
133170

134171
the rendered log message comes out as: `"This is a sensitive ***MASKED***"`
135172

136-
## Never mask a property
173+
### Never mask a property
137174

138175
It may be that you never want to mask the value of a property regardless of whether it matches a pattern for any of the masking operators. In that case you can specify that the property is never masked:
139176

0 commit comments

Comments
 (0)