Implementing Tracing throughout an application

  • Thread starter Thread starter Trace User
  • Start date Start date
T

Trace User

Hello,

I have a design question regarding Tracing and Trace
Switches.

I understand that Trace Switches can be configured through
an application's .config file. When a switch is
instantiated, the application automatically checks the
configuration file for a matching named switch. If there's
a match, the configuration parameters are set.

My question is this: In a non-trivial application that
spans several classes and several modules, would you
declare and instantiate a single trace switch that gets
passed throughout the application where needed? Or would
you declare and instantiate unique switches within the
classes they are needed, making use of the common name
that appears in the .config file.

E.g. Application with 3 classes - Controller, Alpha, and
Beta. Tracing is required in Alpha and Beta.

Would you declare the trace switch in Controller and pass
reference to Alpha and Beta?
OR
Would you declare individual switches in both Alpha and
Beta where required?

Sincerely,

Trace User
 
Trace User said:
Hello,

I have a design question regarding Tracing and Trace
Switches.

I understand that Trace Switches can be configured through
an application's .config file. When a switch is
instantiated, the application automatically checks the
configuration file for a matching named switch. If there's
a match, the configuration parameters are set.

My question is this: In a non-trivial application that
spans several classes and several modules, would you
declare and instantiate a single trace switch that gets
passed throughout the application where needed? Or would
you declare and instantiate unique switches within the
classes they are needed, making use of the common name
that appears in the .config file.

E.g. Application with 3 classes - Controller, Alpha, and
Beta. Tracing is required in Alpha and Beta.

Would you declare the trace switch in Controller and pass
reference to Alpha and Beta?
OR
Would you declare individual switches in both Alpha and
Beta where required?

It depends upon the switch. If the switch is class specific, I declare it
in the class (static). If it's not class specific, I declare it once in
each assembly.
 
I know, this doesn't answer the question below, but as an aside . . .

If you're doing that much tracing, you may want to consider something like
log4net. You can dynamically change the level of tracing that is output by
updating an XML config file, it's fast, stable, and makes tracing really
easy.

We're using it in several projects. It's open source and can be found at
http://log4net.sourceforge.net/

Robert
 
Back
Top