NHibernate 抛出的异常中可以抑制参数值吗? [英] Can parameter values be suppressed in Exceptions thrown by NHibernate?

查看:56
本文介绍了NHibernate 抛出的异常中可以抑制参数值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如 此处 所回答的那样,NHibernate 在遇到 ADO 异常时包括查询的 SQL 以及参数值.由于数据敏感性问题,我需要编辑或抑制发送到数据库的参数值,以免它们最终出现在应用程序日志中.有没有办法配置 NHibernate 使其不包含参数值?或者我可以覆盖以实现这一目标?

As answered here, NHibernate includes the SQL of queries as well as parameter values when it encounters an ADO exception. Due to data sensitivity concerns, I need to redact or suppress the values of parameters that were sent to the database so that they don't end up in application logs. Is there a way to configure NHibernate so that it does not include the parameter values? Or something that I can override to achieve that?

推荐答案

您可以使用自己的自定义方言覆盖 BuildSQLExceptionConverter 用于生成自定义 NHibernate.Exceptions.ISQLExceptionConverter 的方法.(参见其默认实现,或查看测试项目中的示例.)

You may use your own custom dialect overriding the BuildSQLExceptionConverter method for yielding a custom NHibernate.Exceptions.ISQLExceptionConverter. (See its default implementation, or see examples in the test project.)

删除此处的参数值可能意味着对 exceptionInfo 参数的 Message 和/或 Sql 属性值进行了一些肮脏的黑客攻击Convert 方法.

Removing the parameter values here will likely imply some dirty hacking of the Message and/or Sql properties values of the exceptionInfo parameter received by the Convert method.

目前没有办法阻止 NHibernate 格式化这些属性值中的 sql 参数值.

There is currently no way to prevent NHibernate from formatting the sql parameters values in these properties values.

使用自定义方言通常是通过扩展您的应用程序当前使用的方言来完成的,然后使用 dialect 设置.

Using a custom dialect is usually done by extending the one your application is currently using, then configuring it with the dialect setting.

这篇关于NHibernate 抛出的异常中可以抑制参数值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆