Solved

log4net app-domain object

Posted on 2009-05-04
2
199 Views
Last Modified: 2013-11-07
Hi Experts,

I'm using Log4Net instead of .net Tracing for my logging needs.  With tracing, it seems that I can write from wherever I am in code without needing a tracing object (i.e. Trace.Write).  I think that's because .net sets up an app-domain Tracing object?

Is the same possible for Log4Net or do I need to pass around a log object?  I'd love to use Log4Net in the same way as tracing where I can just code Log.Debug("...") and not worry about passing around the Log object.  thoughts?
0
Comment
Question by:sfun28
2 Comments
 
LVL 39

Accepted Solution

by:
abel earned 500 total points
ID: 24297874
Well, with large frameworks like log4net there's usually some kind of "best practice" when it comes to these kinds of questions. In this case, the log4net theme suggests to use a static object per class which can be declared in one line. The most quoted line to use for this is the following, which is the same as I use (VB syntax):

Private Shared m_logger As ILog = _
          LogManager.GetLogger(GetType(MyClassName))
There are other methods you can use. One is, for instance, the one-liner that uses reflection to get the current classname. This is a slightly slower method. It has the benefit of no necessary renaming, but it has the problem of a slightly slower startup time.

Note that tracing is build-in, but when enabled, it is a tremendous impact on the performance of the web site/page. Using a logger, you have much more control via the log4net configuration files and you can even make it monitor the config file so that it will reload it when you change it in a live situation. That has the benefit of "no restarts needed" to change the level of logging.

All in all, log4net is a more powerful and very well performing logging alternative. Tracing can still be handy sometimes (i.e., to follow all events) but will only be used while debugging anyway. Logging will be used for much more than that.

-- Abel --
0
 
LVL 1

Author Closing Comment

by:sfun28
ID: 31577669
Thank so much!!!  This was EXACTLY what I was looking for.  Also, you went above and beyond to provide some very useful information about tracing and logging.  I very much appreciate it.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now