Logging performance and TraceManager

Topics: Logging Application Block
Nov 19, 2008 at 8:15 PM
I am implementing use of the Logging application block.  I was hesitant to scatter code like this all over my app:

Logger.Write("some message");

So I created an interface ILogWriter:

void WriteDebugInfo(string message);
void WriteGeneralInfo(string message);

Then I created 2 global classes that implement my ILogWriter interface:
LogWriterEnterpriseLibrary - uses unity to populate a private Enterprise Library LogWriter and wraps the creation of LogEntry objects for me
LogWriterNullLogger - implements interface with empty methods (so using this class would effectively disable all logging and remove dependency on Logging Application block)

Q1 - Is using the LogWriterNullLogger idea a good one, to improve performance, or just in terms of general architecture?

Looking at the TraceManager:
The examples have me doing this everywhere in the code:

using (traceManager.StartTrace("PerformanceTracing")
{
     //my code
}

Q1 - how would I disable or turn off the TraceManager?  just use a CategoryFilter for the PerformanceTracing category? 
Q2 - is there any performance overhead with this method? 
Q3 - Would I be better off trying to implement my own global accessor to the TraceManager and use a similar idea to the LogWriter so that it could be completely removed when turned off?

Thanks.

Nov 20, 2008 at 5:52 AM
Hi,

If you dont want to scatter your code across, you can try using the PIAB with the Logging Application Block using the LoggingCallHandler. If you want to turn off logging, you can add a LogEnabledFilter to the filters node and set the Enabled property to false.


For your performance question, here are related posts:
http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=7885
http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=3310



Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Nov 20, 2008 at 9:14 PM
I haven't investigated the PIAB yet.  I guess I have to do that.  I figured the PIAB was a bit like Unity on steroids, and we are already using Unity to inject the LogWriterEnterpriseLibrary class or the LogWriterNullLogger class, depending on config.