为什么 AdoNetAppender 不将日志消息写入数据库?

发布于 2024-09-08 14:48:03 字数 2384 浏览 4 评论 0原文

我正在使用 AdoNetAppender 这是我的配置文件的一部分:

 <appender name="ADONetAppender" type="log4net.Appender.ADONetAppender">
  <bufferSize value="1" /> 
  <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  <connectionString value="[we will set this automatically at runtime]" />
  <commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />
   <parameter>
    <parameterName value="@log_date"/> <dbType value="DateTime"/> <layout type="log4net.Layout.RawTimeStampLayout"/>
  </parameter>
       <parameter>
    <parameterName value="@thread"/> <dbType value="String"/> <size value="255"/> <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%thread"/>
    </layout>
  </parameter>
  <parameter>
     <parameterName value="@log_level"/> <dbType value="String"/> <size value="50"/> <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%level"/>
    </layout>
  </parameter>
   <parameter>
     <parameterName value="@logger"/> <dbType value="String"/> <size value="255"/> <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%logger"/>
    </layout>
  </parameter>
   <parameter>
     <parameterName value="@message"/> <dbType value="String"/> <size value="4000"/> <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%message"/>
    </layout>
  </parameter>
   <parameter>
     <parameterName value="@exception"/> <dbType value="String"/> <size value="2000"/> <layout type="log4net.Layout.ExceptionLayout"/>
  </parameter>
</appender>

这是我记录消息的代码:

 private static readonly ILog fifthlog = LogManager.GetLogger("ADONetAppender"); fifthlog.Info("this is db log");

我还使用其他附加器,例如 RollingFileAppender,它们工作正常,但这个却不能,因为当我执行此查询时 select * from Log 在我的 sql server 中,表是空的。我的数据库连接成功,因为我测试了连接。怎么了?

I am using the AdoNetAppender
and here is a portion of my config file:

 <appender name="ADONetAppender" type="log4net.Appender.ADONetAppender">
  <bufferSize value="1" /> 
  <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  <connectionString value="[we will set this automatically at runtime]" />
  <commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />
   <parameter>
    <parameterName value="@log_date"/> <dbType value="DateTime"/> <layout type="log4net.Layout.RawTimeStampLayout"/>
  </parameter>
       <parameter>
    <parameterName value="@thread"/> <dbType value="String"/> <size value="255"/> <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%thread"/>
    </layout>
  </parameter>
  <parameter>
     <parameterName value="@log_level"/> <dbType value="String"/> <size value="50"/> <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%level"/>
    </layout>
  </parameter>
   <parameter>
     <parameterName value="@logger"/> <dbType value="String"/> <size value="255"/> <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%logger"/>
    </layout>
  </parameter>
   <parameter>
     <parameterName value="@message"/> <dbType value="String"/> <size value="4000"/> <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%message"/>
    </layout>
  </parameter>
   <parameter>
     <parameterName value="@exception"/> <dbType value="String"/> <size value="2000"/> <layout type="log4net.Layout.ExceptionLayout"/>
  </parameter>
</appender>

and this is my code to log messages:

 private static readonly ILog fifthlog = LogManager.GetLogger("ADONetAppender"); fifthlog.Info("this is db log");

I'm also using other appenders like RollingFileAppender, and they are working perfectly but this one doesn't, because when I do this query select * from Log in my sql server the table is empty. My db connection is successful because I tested the connection. What's wrong?

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

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

发布评论

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

评论(2

浅浅淡淡 2024-09-15 14:48:03

为了真正找出发生的情况,您应该启用内部调试:

http://log4net.sourceforge.net/release/1.2.0.30316/doc/manual/faq.html#internalDebug

我想到的一些事情:

  • 数据库的权限问题(如所指出的by devstuff 已经)
  • 如果您使用集成安全性:您可能会与调用者而不是主机进程连接(例如,如果您有共享点环境,则会发生这种情况)。
  • 您的参数之一存在转换问题(尽管这似乎不太可能)

In order to really find out what is happening you should enable internal debugging:

http://log4net.sourceforge.net/release/1.2.0.30316/doc/manual/faq.html#internalDebug

A few things that come to my mind:

  • Permission issue on the database (as pointed out by devstuff already)
  • If you use integrated security: It could be that you connect with the caller instead of the host process (this happens for instance if you have a sharepoint environment).
  • Conversion problem with one of your parameters (though this seems unlikely)
在你怀里撒娇 2024-09-15 14:48:03

该帐户是否具有 Log 表的插入权限?

该附加器的配置输出级别是多少?

Does the account have insert permissions on the Log table?

And what is the configured output level for this appender?

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