views:

480

answers:

2

I need to trace all method calls in an ASP.NET application for a period of time, say 24 hours, into a log file. Looking for tools that allows me to do this? I'm interested in in getting something like this out:

2009-10-12T13:00:41 MyClass.MyMethod("arg1.toString()", "arg2.toString()") 
... other nested calls inside this method ...
2009-10-12T13:00:42 MyClass.MyMethod() 0.2312 seconds

Basically a way to see how long each method call took and what input it got.

A: 

You should have a look at PostSharp, which can provide that kind of functionality

From the samples on the home 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);   } 
}

Then apply this trace attribute to the methods you want to trace :

[Trace]
public void MyMethod(int myArg)
{
}

I think you can also use ELMAH (which is probably more flexible), but I never used it myself...

Thomas Levesque
But this would mean that I need to edit every method myself? That's like... 5.000 methods
thr
Plus it would be nice to trace methods that I don't have the source for
thr
Check out ELMAH (second link in my answer), it doesn't require any modification to to your code (if I understand correctly...)
Thomas Levesque
+1  A: 

You might want to look at ANTS Profiler. It can give you line by line execution time and has an option to do .NET framework code as well as your own.

Rob West
this. Yes I realized yesterday I could use the ANTS Profiler for it, it's been running all night and works awesomely.
thr