在EF Core中执行SQL跟踪期间丢失参数值 [英] Lost parameter value during SQL trace in EF Core
问题描述
根据本文,我已经实现了一种从EF Core跟踪SQL查询的方法:
我正在使用VS2015。谢谢!
这是EF Core的默认行为(填充 DbParameterLogData.Value
属性?
)。
为了获取真实的参数值,您需要使用 DbContextOptionsBuilder.EnableSensitiveDataLogging
方法:
使应用程序数据可以包含在异常消息,日志记录等中。这可以包括分配给实体实例属性的值, 要发送到数据库的命令的参数值以及其他此类数据。仅在根据数据的敏感性采取适当的安全措施后,才应启用此标志。
保护的重写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 parameteres. When I recive Log event in all values of DbParameterLogData I see only the question mark instead of the actual values wich I passed to the query.
I am using VS 2015. Thank you!
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屋!