Converting log4net level by configuration
We have a legacy logging database that logs two types of occurrences.
- Error
- 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.
精彩评论