serilog-contrib / Serilog.Enrichers.Sensitive

A Serilog LogEvent enricher that masks sensitive data
MIT License
111 stars 23 forks source link

Different configuration for different sink types #34

Open mikewop opened 8 months ago

mikewop commented 8 months ago

Is it possible to have different configurations for different types of sinks? E.g. mask different/less items in log entries going to a file sink vs one going to Azure Application Insights or NewRelic etc.

Or if that's not possible only apply the enricher to certain sink types?

sandermvanvliet commented 7 months ago

That's a good question and not something I've looked into before.

A quick search reveals this StackOverflow answer that you can use a sub-logger like so:

Log.Logger = new LoggerConfiguration()
    .WriteTo.File("app.log") // This doesn't have the sensitive data scrubbing
    .WriteTo.Logger(lc => lc
        .Enrich.WithSensitiveDataMasking()
        .WriteTo.ApplicationInsights() // This will get sensitive data scrubbing
    .CreateLogger();

which would give you a bunch of flexibility.

Would that help?

mikewop commented 7 months ago

Yes thank you, I had come across that too. But I am not sure if you can configure a sublogger using the appsettings.json file ? e.g. I'd like to configure this in the settings file

   "Using": [
      "Serilog.Enrichers.Sensitive"
    ],
    "Enrich": [
      {
        "Name": "WithSensitiveDataMasking",
        "Args": {
          "options": {
            "MaskProperties": [
              "UserName"
            ],
            "ExcludeProperties": [
              "EmailAddresses"
            ],
            "Mode": "Globally"
          }
        }
      }
    ]
sandermvanvliet commented 6 months ago

No idea if that's possible. The JSON configuration is fairly limited in this regard and configuring through code gives you much more options and granularity so I would recommend doing that instead.