Solved

log4net app-domain object

Posted on 2009-05-04
2
201 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

839 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