Log4Net ADO.net 信息缓冲区

发布于 2024-07-26 23:36:05 字数 2545 浏览 3 评论 0原文

有没有一种方法可以将 AdoNetAppender 配置为在每次达到“错误”类型的值时进行记录,并且仅记录该语句之前的下限阈值(即信息)的最后 10 个语句。

那可能吗? 我正在为每个错误运行数百个 .Info 语句,但我不需要那么多......足以了解之前发生的情况。

编辑 - 这是我当前的附加程序配置:

    <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
  <bufferSize value="10" />
  <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXX" />
  <connectionString value="Data Source=XXXXXXX; Database=XXXXXXXXXXX; User Id=XXXXXXX; Password=XXXXXXXX; Connection Timeout=30; Min Pool Size=10; Max Pool Size=200;" />
  <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>
<root>
  <level value="ALL" />
  <appender-ref ref="AdoNetAppender" />
  <appender-ref ref="AspNetTraceAppender" />
</root>

谢谢, 凯尔

Is there a way I can configure the AdoNetAppender to log every time a value of type 'Error' is reached, and log only the last 10 statements of lower threshold (i.e. info) prior to that statement.

Is that possible? I'm running up hundreds of .Info statements for each individual error and I don't need that many... just enough to see what happened right beforehand.

edit - here is my current appender configuration:

    <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
  <bufferSize value="10" />
  <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXX" />
  <connectionString value="Data Source=XXXXXXX; Database=XXXXXXXXXXX; User Id=XXXXXXX; Password=XXXXXXXX; Connection Timeout=30; Min Pool Size=10; Max Pool Size=200;" />
  <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>
<root>
  <level value="ALL" />
  <appender-ref ref="AdoNetAppender" />
  <appender-ref ref="AspNetTraceAppender" />
</root>

Thanks,
Kyle

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

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

发布评论

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

评论(1

梦里的微风 2024-08-02 23:36:05

在这里找到了解决方案:
http://www.beefycode.com/post/Log4Net -Tutorial-pt-8-Lossy-Logging.aspx

  <lossy value="true"/>
  <evaluator type="log4net.Core.LevelEvaluator">
    <threshold value="ERROR" />
  </evaluator>

Found the solution here:
http://www.beefycode.com/post/Log4Net-Tutorial-pt-8-Lossy-Logging.aspx

  <lossy value="true"/>
  <evaluator type="log4net.Core.LevelEvaluator">
    <threshold value="ERROR" />
  </evaluator>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文