?
Solved

log4net app-domain object

Posted on 2009-05-04
2
Medium Priority
?
205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 39

Accepted Solution

by:
abel earned 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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.   …
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

801 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