开发者

Converting log4net level by configuration

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 con开发者_StackOverflowditional logic in the value of conversionPattern?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜