Recently, I switched to a lot of diagnostic logging template in parts of my code that uses lambda expressions / anonymous delegates:
MyEventManager.LogVerbose( LogCategory.SomeCategory, () => String.Format(msg_string, GetParam1(), GetParam2(), GetParam3() );
Note that the second argument to LogVerbose is a lambda expression that evaluates to a string. The reason for this is that if slave logging is not actually allowed, LogVerbose should exit with as little work as possible to minimize performance impact. Building an error message line may in some cases take time or resources, and if the lambda expression is never evaluated, this performance penalty will not be incurred.
I am wondering if a type system with as many anonymous delegates as this can get clogged will have some unforeseen consequences for application performance or if there are any other strategies that I should consider.
source
share