views:

242

answers:

3

What is tracing and how should it be done?

I have a common utilities library I am including in my projects and I want to be able to get some output from it. I have been using log4net but would rather not have my common utilities library dependent upon log4net. Does that make sense?

Edit: Is there any correlation between logging and tracing? Would I want to put tracing and logging into the same stream for some reason?

Should I perhaps replace some of the log4net Logger.Debug(..) I have in my projects with System.Diagnostics.Trace.WriteLine(..)s?

+1  A: 

Here are some blog posts by Mike Rousos of the .NET BCL team:

Mark Cidade
A: 

Would it not just be easier (read better) to use log4net in all of your projects and libraries. In this way the projects can specify how they want to log stuff and your common library's logging would just listen to the project.

If you have a custom logger for your common library you will end up having common logs in one place and application (project) logs in another place.

For an example of this you can look at NHibernate or Castle ActiveRecord. Both of these could be considered "common utilities" (they are doing your data access). They both make use of log4net. So by using them in your project, and using log4net as your project logger you can specify that all your logging data goes to one place.

Should you want to you could even set up the different loggers in different ways. So as to log your common logs at INFO level and your project logs at ERROR.


I just found another question on tracing VS logging it seems to be quite in deapth. Take a look at it. Maybe it will help out. Tracing versus Logging and how does log4net fit in?

FryHard
A: 

I agree with FryHard, or better extend log4net with your custom classes.

kenny