I have written a large C# app with many methods in many classes.
I'm trying to keep a log of what gets called and how often during my development. (I keep a record in a DB)
Every method is padded with the following calls:
void myMethod()
{
log(entering,args[]);
log(exiting,args[]);
}
Since I want to do this for all my methods, is there a better way to do this then having to replicate those lines of code in every method?
Take a look at http://www.postsharp.org/
Here's the first example on their front page:
public class TraceAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionEventArgs eventArgs)
{ Trace.TraceInformation("Entering {0}.", eventArgs.Method); }
public override void OnExit( MethodExecutionEventArgs eventArgs)
{ Trace.TraceInformation("Leaving {0}.", eventArgs.Method); }
}
Seems to be exactly what you need!
Well, you could use some kind of Decorator on your classes to log things, but I think the better approach is to use some kind of profiling tool in your build and/or unit testing process. You can pretty easily get a lot of value out of some simple metric collection in CruiseControl, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With