Hi!
I plan to put a call to MethodBase.GetCurrentMethod() at the beginning of most methods (for informative logging), but since this would present a high overhead, it would be good if a conditional attribute could be used used like:
#define LogMethodNames
where...
[Conditional("LogMethodNames")]
was put above every line call GetCurrentMethod(), like:
void DoStuff()
{
[Conditional("LogMethodNames")]
logger.CurrentMethod = MethodBase.GetCurrentMethod();
// stuff done here
}
...so at least it could be excluded from release builds.
Is something along these lines possible?
Thanks!
Gregg
PS I would try this myself now but for some reason I couldn't get Attributes to work due to a compile error. Doh.
PPS If this can't work I'd create a method which assigns to the logger object, like:
void SetCurrentMethod(MethodBase currentMethod)
{
logger.CurrentMethod = currentMethod;
}
and use:
void DoStuff()
{
[Conditional("LogMethodNames")]
SetCurrentMethod(MethodBase.GetCurrentMethod());
// stuff done here
}
Any thoughts?! Thanks :-)