开发者

Logging Application Block - The cost of Logger.Write()

开发者 https://www.devze.com 2023-01-11 12:42 出处:网络
HI All, How costly can 开发者_如何学Gobe Logger.Write(logEnrty) with respect to the CPU cycles when we are considering the application performance. I\'m going to assume .NET/Visual Studio here (given

HI All,

How costly can 开发者_如何学Gobe Logger.Write(logEnrty) with respect to the CPU cycles when we are considering the application performance.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消