thr
thr

Reputation: 19476

Trace all method calls in ASP.NET application

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.

Upvotes: 5

Views: 7840

Answers (2)

Rob West
Rob West

Reputation: 5241

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.

Upvotes: 3

Thomas Levesque
Thomas Levesque

Reputation: 292765

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...

Upvotes: 2

Related Questions