Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 715
Poul K. Sørensen Avatar asked Feb 12 '18 18:02

Poul K. Sørensen


1 Answers

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:

  • SeriLog.LogSanitizingFormatter
  • Destructurama.attributed
  • Destructurama.ByIgnoring
like image 89
Devin Goble Avatar answered Oct 14 '22 16:10

Devin Goble