Search code examples
.net.net-core.net-core-logging

Removing sensitive information from logs in ASP.NET Core logging


I am using ASP.NET Core logging abstraction for my application.

I have a list of sensitive strings that i would like to make sure is masked "*****" in the logs when sent to any sinks. (I am using serilog - but maybe it can be plugged in even before serilog).

How would I plug this into the ASP.NET Core logging system to replace all these sensitive strings with "*******" before sent to any sinks / writers etc.


Solution

  • Without knowing what you are trying to scrub, there are a few options.

    There are several good ideas in this GitHub issue.

    To summarize the thread: You can use an enricher to completely wipe the contents of a property. You could also use a text formatter to manually run regex replacements.

    There are also a few packages mentioned that you can add to provide more structure around processing your log: