Log4Net ADO.net信息缓冲区

时间:2009-07-12 23:09:48

标签: asp.net log4net

有没有办法可以配置AdoNetAppender每次达到“错误”类型的值时记录,并在该语句之前仅记录最低10个较低阈值(即信息)的语句。

这可能吗?我为每个错误运行了数百个.Info语句,我不需要那么多......只是足以看到事先发生的事情。

编辑 - 这是我当前的appender配置:

    <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>

谢谢, 凯尔

1 个答案:

答案 0 :(得分:5)

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

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