log4net in C#

  • Thread starter Thread starter Raymond Chiu
  • Start date Start date
R

Raymond Chiu

Dear all,

I find log4net in the following link.
http://sadi02.wordpress.com/2008/06/29/log4net-tutorial-in-c-net-how-can-i-show-log-in-a-file/

In point 5.
5. To use log4net put this as a local class variable: protected
static readonly ILog log =
LogManager.GetLogger(Program);

How to avoid to put "protected static readonly ILog log =
LogManager.GetLogger(Program);" in every aspx.cs??

As if we need to put this line in every class, it will be troublesome.

Do you have any ideas???
 
The problem is that it needs the data type of the class that is
logging in the constructor rather than the method to log some text.
Putting it in every class is not a bad option: cut, paste, change the
data type.
 
Raymond said:
I find log4net in the following link.
http://sadi02.wordpress.com/2008/06/29/log4net-tutorial-in-c-net-how-can-i-show-log-in-a-file/

In point 5.
5. To use log4net put this as a local class variable: protected
static readonly ILog log =
LogManager.GetLogger(Program);

How to avoid to put "protected static readonly ILog log =
LogManager.GetLogger(Program);" in every aspx.cs??

As if we need to put this line in every class, it will be troublesome.

Do you have any ideas???

The point in log4net is that you can control log output at a very
fine level.

To do that you need something for every class. Which is what you
supply here.

If you need to do logging in classes without adding code to the classes,
then you need to look at an AOP framework.

Arne
 
Back
Top