serilog-contrib / Serilog.Enrichers.Sensitive

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

Masking >1 Properties of a Serialized object #39

Closed jeeby closed 4 months ago

jeeby commented 4 months ago

Posted on closed ticket, but posting again for visibility... Original post: https://github.com/serilog-contrib/Serilog.Enrichers.Sensitive/issues/15

My issue: I'm having a very similar issue to this one.. when trying to mask certain properties in a json payload, it's only masking the email field. No matter what I try, only the email field gets masked.

Payload looks like this (after masking): {"FirstName":"Greg","LastName":"Berlin","Email":"**","LocationCode":"M010","ItemCodes":["I-025400"]}

This is my config:

"Enrich": [
  {
    "Name": "WithSensitiveDataMasking",
    "Args": {
      "options": {
        "MaskValue": "******",
        "MaskProperties": [
          "FirstName",
          "LastName",
          "Email"
        ],
        "Mode": "Globally"
      }
    }
  }
]

I've tried having just a single MaskProperty instead of 3 of them, but still only email gets masked (even when I specify FirstName for example.

Any ideas what I'm doing wrong? Is this supposed to work? All your tests linked above only have a single field being masked, can you do one with more than 1 field?

Anything else I can try to get this working?

Thanks

jeeby commented 4 months ago

Nevermind, I got it working. Turned out I just needed to use structured logging to make i work.

For other's reference, I had this before:

LoggingService.Info($"{GetType().Name} | Creating NotificationRequest records | Request: {JsonConvert.SerializeObject(createRequest)}");

Had to change to this:

LoggingService.Info("{TypeName} | Creating NotificationRequest records | Request: {@request}", GetType().Name, createRequest);