serilog-contrib / Serilog.Enrichers.Sensitive

A Serilog LogEvent enricher that masks sensitive data
MIT License
121 stars 24 forks source link

Masking properties with Full Name #40

Open kostyrin opened 2 months ago

kostyrin commented 2 months ago

Is it possible to use MaskingProperties with full name. I mean with namespace like Project1.Class1.Property1. like

var logger = new LoggerConfiguration()
    .Enrich.WithSensitiveDataMasking(options => options.MaskProperties.Add("Project1.Class1.Property1"))
    .WriteTo.Console()
    .CreateLogger();

We have different classes with same property names. We would like to mask properties in curtain classes. Thank for any advice.

sandermvanvliet commented 2 months ago

Let me see if I understand what you’re trying to accomplish before I offer a suggestion 🙂

From what you’re writing you have a number of classes like this (other properties omitted):

class NamespaceOne.ClassOne {
    public string Thing { get; }
}

class NamespaceTwo.ClassTwo {
    public string Thing { get; }
}

class NamespaceThree.ClassThree {
    public string Thing { get; }
}

and what you want to achieve is that (for example) you only want the property Thing for ClassThree to be masked but for ClassOne and ClassTwo no masking of that property should happen.

Is that correct?

kostyrin commented 1 month ago

correct

kostyrin commented 1 month ago

would you provide any advices?

sandermvanvliet commented 1 month ago

I've experimented a bit and it turns out this is not possible to achieve unfortunately due to the fact that when the masking runs we don't have the necessary type information anymore to make any kind of masking decision.

An alternative would be to use sensitive areas in the places where you do want to mask the given property. That might give you enough control to work with for your scenario.