log4net in C#

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???
 
N

not_a_commie

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.
 
A

Arne Vajhøj

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top