views:

426

answers:

1

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

+2  A: 

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>
Kyle B.
Feels good to answer one's own questions doesn't it ;)
Peter Lillevold
Indeed it does, sort of like winning a small victory :)
Kyle B.