Closed zyofeng closed 6 months ago
Hi @zyofeng, thanks for dropping by! This would be nice to see :+1:
It's not really in scope for this repository, and I'm not sure if any Serilog maintainers have time carved out for it right now; perhaps NZ Funds would be open to publishing this independently as an add-on package, in the same way that the Destructurama packages are published?
Happy to take this one and create a separate package. But I would need some suggestion on how to handle IRedactorFactory dependancy, my understanding of serilog design is that it's agnostic to the underlying DI library?
Hi Mike,
Yes, that's normally the case - when using Serilog.Extensions.Hosting, however, there's an AddSerilog()
overload that provides IServiceCollection
, from which the factory can be retrieved:
builder.Services.AddSerilog((services, loggerConfiguration) => loggerConfiguration
.Destructure.WithRedaction(services.GetRequiredService<IRedactorFactory>()))
(I'm not 100% sure of the parameter ordering etc., but this should be pretty close :-))
Keen to hear how you go, and please drop me a line if you need any more info.
I've put something together, feedbacks are welcome
https://github.com/zyofeng/serilog-redaction/tree/master/src
Looks great! :+1:
Currently I'm using Destructurama.Attributed to redact sensitive information in the logs. That is quite static, and would be nice to be able to customize redaction using Microsoft.Extensions.Compliance.Redaction and more precisely through DataClassification attribute.
Something like this (adapted from Destructurama.Attributed):