extensions icon indicating copy to clipboard operation
extensions copied to clipboard

Improve discoverability of DI prerequisites in AspNetCore.Diagnostics.Middleware package

Open iliar-turdushev opened this issue 2 years ago • 0 comments

Similar to #4675.

Currently if you want to enable either HttpLogging enrichment or redaction you have to know that you need to reference Microsoft.Extensions.Compliance.Redaction package and register AddRedaction() in the IServiceCollection. If you don't do that you'll get an exception saying that service container cannot find IRedactorProvider. As a solution, we can make IRedactorProvider optional, and use NullRedactor when it is not registered.

Another issue is that AddHttpLogEnricher in addition to registering HttpLogEnricher registers redaction. It could be unobvious from user's perspective. For example, a user registers only HttpLogEnricher and he/she doesn't expect that it will require IRedactorProvider, but the package will and during start up the application will throw the exception mentioned above.

iliar-turdushev avatar Nov 08 '23 11:11 iliar-turdushev