Read the doc before diving, log4net on demand

My boss gave me a task, creating something like log-on-demand feature in our apps.

Spec:

  1. Be able to define a global threshold for all classes to log.
  2. Be able to add some exception classes with threshold override the predefined global one.

As usually, I google, tried, iisreset, re-try… filter, chained, …

It turns out this is a STANDARD out-of-box feature from log4net, and I actually have been used this since day 1, to control the NHibernate logger threshold in our app.

 	  <root>
 	    <level value="INFO" />
 	    <appender-ref ref="AdoNetAppender" />
 	  </root>
 	  <logger name="NHibernate">
 	    <level value="ERROR"/>
 	  </logger>
 	  <logger name="OneProblemClass">
 	    <level value="DEBUG"/>
 	  </logger>

See logger section from official log4net configuration doc.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s