Lost parameter value during SQL trace in EF Core

I applied the approach for tracking SQL queries from EF Core according to this article: https://docs.microsoft.com/en-us/ef/core/miscellaneous/logging . And there are problems with tracking request parameters. When I get a log event in all DbParameterLogData values, I see only a question mark instead of the actual values ​​that I passed to the request. Sample image of VS 2015. Thank you!

+6
source share
1 answer

This is the default behavior of EF Core (filling property DbParameterLogData.Valuewith "?").

To get real parameter values, you need to enable confidential data logging using the method DbContextOptionsBuilder.EnableSensitiveDataLogging:

Allows you to include application data in exception messages, logging, etc. This may include values ​​assigned to the properties of entity instances, parameter values ​​for commands sent to the database , and other such data. You should enable this flag only if you have appropriate security measures based on the sensitivity of this data.

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    optionsBuilder.EnableSensitiveDataLogging();
    // ...
}
+9
source

All Articles