禁用 NHibernate 日志记录

发布于 2024-08-06 04:41:35 字数 421 浏览 5 评论 0原文

我有一个 app.config 文件,但我仍然收到 NHibernate 调试日志

NHibernate: SELECT this_.LogID as LogID71_0_, this_.Level as Level71_0_, this_.Message as Message71_0_, this_.EventTime as EventTime71_0_, this_.Component as ...

我尝试添加具有错误日志级别的 log4net 配置,但没有用。我怎样才能停止这些日志消息?

我感到困惑的是,如果我有一个空的 app.config ,为什么这些会首先出现。我必须将其配置为不打印这些消息对我来说没有意义 - 默认值应该关闭。难道是我的代码以某种方式以编程方式设置它们?我应该寻找什么?

I have an empty app.config file, but I still get NHibernate debug logs

NHibernate: SELECT this_.LogID as LogID71_0_, this_.Level as Level71_0_, this_.Message as Message71_0_, this_.EventTime as EventTime71_0_, this_.Component as ...

I tried adding a log4net configuration with an ERROR log level, but no use. How can I stop these log messages?

The thing I'm puzzled about is why do these appear in the first place if I have an empty app.config to being with. It doesn't make sense to me that I have to configure it not to print these messaages - the default should be off. Could it be my code is setting them on programatically somehow? What should I look for?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

染柒℉ 2024-08-13 04:41:35

配置 Log4Net 以与 NHibernate 一起使用可能会有所帮助。

您需要拥有这两个记录器:

 <logger name="NHibernate">
   <level value="ERROR" />
 </logger>

 <logger name="NHibernate.SQL">
   <level value="ERROR" />
 </logger>

Configure Log4Net for use with NHibernate may be helpful.

You need to have both these loggers:

 <logger name="NHibernate">
   <level value="ERROR" />
 </logger>

 <logger name="NHibernate.SQL">
   <level value="ERROR" />
 </logger>
峩卟喜欢 2024-08-13 04:41:35
return Fluently.Configure()
            .Database(MsSqlConfiguration.MsSql2005.ConnectionString(
                c => c.FromConnectionStringWithKey("MyDB")).ShowSql())

删除 .ShowSql() 对我有用

return Fluently.Configure()
            .Database(MsSqlConfiguration.MsSql2005.ConnectionString(
                c => c.FromConnectionStringWithKey("MyDB")).ShowSql())

Removing the .ShowSql() worked for me

烟燃烟灭 2024-08-13 04:41:35

问题出在“我的代码”中的某个地方。我们手动构建 NHibernate 配置(将 show_sql 标志设置为 true)。

The problem was somewhere in "my code". We build the NHibernate configuration manually (setting the show_sql flag to true).

晚雾 2024-08-13 04:41:35

NHibernate 日志对我没有多大帮助...我更喜欢这些设置:

    <logger name="NHibernate">
      <level value="OFF" />
    </logger>

    <logger name="NHibernate.SQL">
      <level value="OFF" />
    </logger>

The NHibernate logs don't help me much... I like these settings better:

    <logger name="NHibernate">
      <level value="OFF" />
    </logger>

    <logger name="NHibernate.SQL">
      <level value="OFF" />
    </logger>
恏ㄋ傷疤忘ㄋ疼 2024-08-13 04:41:35

您想要禁用 NHibernate 级别还是 Log4Net 级别的日志记录吗?

我通过将“show_sql”变量设置为 false 来执行前者。我现在正在用 C# 以编程方式执行此操作,但我认为这也很容易放入 XML 配置文件中。

Do you want to disable the logging at the NHibernate level or the Log4Net level?

I'm doing the former by setting "show_sql" variable to false. I'm doing this programmatically in C# right now, but I assume this would be easy to put in an XML configuration file as well.

捂风挽笑 2024-08-13 04:41:35

对我来说这是 NUnit 问题。在 TeamCity 中运行测试时会发生额外的日志记录,该测试必须使用不同版本的 nunit

For me it was the NUnit problem. The extra logging was happening when running the tests in TeamCity which must have been using a different version of nunit

芸娘子的小脾气 2024-08-13 04:41:35

您使用的是 NUnit 2.4.6 吗?我读了昨天的博客文章说这个版本的 NUnit 将 log4net 设置为使用 DEBUG 级别日志记录,这也影响了 NHibernate。

如果它不是 NUnit 并且不是你,我会检查它是否是你正在使用的其他第三方库。

编辑

再想一想,我不认为输出与 log4net 有关。格式看起来更像是“show_sql”控制的输出。我会检查两件事:
1. 如果正确的(show_sql=false 的)hibernate.config 被复制到您的执行目录。
2. 如果未在代码中手动覆盖 show_sql 配置属性。

Are you using NUnit 2.4.6? I read this blog post yesterday which says that this version of NUnit sets log4net to use DEBUG level logging, effecting NHibernate as well.

if it's not NUnit and it's not you, I would check if it's some other 3rd party library that you're using.

EDIT

On second thought, I don't think that the output has something to do with log4net. the format looks more like the "show_sql" controlled output. I would check two things:
1. If the correct (the one with the show_sql=false) hibernate.config is copied to your execution directory.
2. If the show_sql configuration property is not overridden manually in your code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文