Solved

log4net app-domain object

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 - Windows Protected Your PC 7 53
Function after success of Jquery/AJAX action 9 45
SSIS GUID Variable 2 36
locate sql commands in C# visual studio Project 6 44
Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 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