Log4Net Appender 未加载

发布于 2024-10-12 19:59:19 字数 3217 浏览 3 评论 0原文

Log4Net 无法加载 DB2 连接的附加程序,我不明白为什么。它可以正常地将日志写入文件系统,但是 DB2 日志记录没有发生。 Log4Net 的版本是v1.2.10.0

<log4net>
  <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
    <bufferSize value="100" />
    <connectionType value="IBM.Data.DB2.DB2Connection,IBM.Data.DB2, Version=8.1.2.1" />
    <connectionString value="server=db2Server;database=dbName;user Id=userId1;password=password;persist security info=true" />
    <commandText value="INSERT INTO GOSDDL.EXCEPTION_LOG (APP_LOG_TS,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">
        <conversionPattern value="%utcdate" />
      </layout>
    </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>

  <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
    <file value="../logs" />
    <appendToFile value="true"/>
    <maximumFileSize value="512KB"/>
    <maxSizeRollBackups value="2"/>
    <rollingStyle value="Date"/>
    <datePattern value=".yyyy-MM-dd.lo" />
    <staticLogFileName value="false" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%d %l %-2p - %m%n"/>
    </layout>
    <filter type="log4net.Filter.LevelRangeFilter">
      <levelMin value="INFO"/>
      <levelMax value="FATAL"/>
    </filter>
  </appender>

  <root>
    <level value="INFO"/>
    <appender-ref ref="RollingFile"/>
  </root>
</log4net>

Log4Net isn't able to load the appender for the DB2 connection and I cannot see why. It writes the logs to the file system fine, however, the DB2 logging isn't occurring. The version of Log4Net is v1.2.10.0.

<log4net>
  <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
    <bufferSize value="100" />
    <connectionType value="IBM.Data.DB2.DB2Connection,IBM.Data.DB2, Version=8.1.2.1" />
    <connectionString value="server=db2Server;database=dbName;user Id=userId1;password=password;persist security info=true" />
    <commandText value="INSERT INTO GOSDDL.EXCEPTION_LOG (APP_LOG_TS,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">
        <conversionPattern value="%utcdate" />
      </layout>
    </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>

  <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
    <file value="../logs" />
    <appendToFile value="true"/>
    <maximumFileSize value="512KB"/>
    <maxSizeRollBackups value="2"/>
    <rollingStyle value="Date"/>
    <datePattern value=".yyyy-MM-dd.lo" />
    <staticLogFileName value="false" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%d %l %-2p - %m%n"/>
    </layout>
    <filter type="log4net.Filter.LevelRangeFilter">
      <levelMin value="INFO"/>
      <levelMax value="FATAL"/>
    </filter>
  </appender>

  <root>
    <level value="INFO"/>
    <appender-ref ref="RollingFile"/>
  </root>
</log4net>

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

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

发布评论

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

评论(1

扛刀软妹 2024-10-19 19:59:19

冒着指出显而易见的风险,您发布的配置文件实际上并未使用 AdoNetAppender。这是否是在倒数第二行用 AdoNetAppender 替换 RollingFile 的问题?

如果没有,您可以发布配置文件的其余部分吗?

At the risk of pointing out the obvious, the config file you posted does not actually use AdoNetAppender. Would this be a matter of replacing RollingFile with AdoNetAppender in the second last line?

If not, can you post the rest of the config file.

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