views:

43

answers:

1

HI All,

How costly can be Logger.Write(logEnrty) with respect to the CPU cycles when we are considering the application performance.

A: 

I'm going to assume .NET/Visual Studio here (given the name "Enterprise Library")

There is more to application performance than CPU cycles. I'm not familiar with the Enterprise Library logger, but I expect the biggest hit in logging isn't in CPU cycles, but in disk IO. If your application is disk IO heavy, logging will affect it more than if it is not.

My recommendation: if you want/need the logging, add it in such a fashion that it is easily disabled from a global standpoint. Instead of calling the logging library directly, wrap it in your own class, so you can disable it in there easily by wrapping it with something like a DEBUG pre-processing directive. And, so as to not hold up your primary execution thread, do your logging on a different thread (not sure if Enterprise Library does that by default)

class MyLogger
{
    public static void Log(string msg)
    {
        #if DEBUG 
           // Logging code here
        #endif
    }
}

What the preprocessing directive above does is it will only build the wrapped code when your Visual Studio DEBUG mode is set. It will not for RELEASE mode.

And, if you really REALLY need to know, grab a profiling tool, and get some real data on what the logging is costing you.

Matt