Open mikewop opened 8 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?
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"
}
}
}
]
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.
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?