hshah
hshah

Reputation: 841

Log4Net - Set conversionPattern for Level Type

I am trying to set up Log4Net in my C# WinForms App.config and would like to set different conversionPattern for Debug/Fatal/Info etc. Does anyone know how to do this?

Upvotes: 4

Views: 2564

Answers (3)

IsraelKo
IsraelKo

Reputation: 116

you can use pattern layout converter https://devstuffs.wordpress.com/2012/01/12/creating-your-own-pattern-layout-converter-for-log4net/

In the convert function you get the log level and then you can provide pattern depends on the level.

Upvotes: 1

ErnieL
ErnieL

Reputation: 5801

You can only do one conversion pattern per appender. However Appenders can have level filters. You could create a different appender for each conversion pattern and then apply the appropriate filter. For example:

<appender>
  <filter type="log4net.Filter.LevelMatchFilter">
    <levelToMatch value="ERROR"/>
  </filter>
</appender>

This log4net Tutorial has all the details.

Upvotes: 5

cobolstinks
cobolstinks

Reputation: 7153

I'm pretty sure its not possible to assign a different conversion pattern on an appender per log level.

You could create multiple appenders with differing thresholds and setup different conversion patterns per appender. This still wont get you 100% of what you're after however.

Upvotes: 2

Related Questions