Solved

log4net app-domain object

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

19 Experts available now in Live!

Get 1:1 Help Now