在 EF Core 中的 SQL 跟踪期间丢失参数值 [英] Lost parameter value during SQL trace in EF Core
问题描述
我根据这篇文章实现了一种从 EF Core 跟踪 SQL 查询的方法:
我使用的是 VS 2015.
这是 EF Core 的默认行为(填写 DbParameterLogData.Value
属性与 "?"
).
为了获得真实的参数值,您需要使用DbContextOptionsBuilder.EnableSensitiveDataLogging
方法:
允许应用程序数据包含在异常消息、日志记录等中.这可以包括分配给实体实例的属性的值、发送到数据库的命令的参数值,以及其他类似的数据.仅当您根据此数据的敏感性采取了适当的安全措施时,才应启用此标志.
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder){optionsBuilder.EnableSensitiveDataLogging();//...}
I have implemented an approach for tracing SQL queries from EF Core according to this article: https://docs.microsoft.com/en-us/ef/core/miscellaneous/logging. And have problems with tracing query parameters. When I receive Log events in all values of DbParameterLogData I see only the question mark instead of the actual values which I passed to the query.
I am using VS 2015.
This is the default behavior of EF Core (filling up the DbParameterLogData.Value
property with "?"
).
In order to get the real parameter values, you need to enable sensitive data logging by using DbContextOptionsBuilder.EnableSensitiveDataLogging
method:
Enables application data to be included in exception messages, logging, etc. This can include the values assigned to properties of your entity instances, parameter values for commands being sent to the database, and other such data. You should only enable this flag if you have the appropriate security measures in place based on the sensitivity of this data.
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.EnableSensitiveDataLogging();
// ...
}
这篇关于在 EF Core 中的 SQL 跟踪期间丢失参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!