0
votes

We have a legacy logging database that logs two types of occurrences.

  1. Error
  2. Event

We've retrofitted log4net to the application, and we're using an AdoNetAppender to log to this legacy database. The stored procedure used to log occurrences takes a stored procedure with one parameter called @TypeID Currently we've configured that parameter like this:

  <parameter>
    <parameterName value="@TypeID" />
    <dbType value="Int32" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="2" />
    </layout>
  </parameter>

This logs all occurrences as events (Type 2), regardless of the event level (error or otherwise). How can I change the configuration so that all occurrences of log4net ERROR or higher would set the @TypeID parameter to 1?

Asked another way:

Is it possible to use conditional logic in the value of conversionPattern?

1

1 Answers

2
votes

You can write a PatternLayoutConverter that does this. I posted a sample which could be easily modified to convert the log levels according to your requirements.