views:

133

answers:

4

Is it possible to log calls of .NET methods made while an application is running?

+1  A: 

Yes. I normally use this: http://www.jetbrains.com/profiler/ (there's a free trial).

Luca Farber
Will it log the actual calls of methods including parameters/arguments?
Craig Johnston
+1  A: 

Perhpas you are interested in one of the following options:

  1. Use existing profiler to visualise calls of .NET methods. It depends on profiler and their functionality but ANTS or DotTrace work just fine if you don't need something absolutely special.

  2. If you are interested in low-level implementation including heap state at the moment of the call then you might be interested in WinDBG + Sos and its tracing options (wt command). Just set breakpoints in WinDbg, run app and collect traces including low level calls.

  3. In case there is a implicit requiremt to log you can use .NET profiling API (C++) and log everything you want to or profiling API from dotTrace profiler (C#) (it is shiped with dotTrace).

    Hope it helps.

Andrei Taptunov
I simply need to know the calls being made and their arguments. What will allow this?
Craig Johnston
Try 2nd way. "Start windbg -> load sos dll -> !CLRStack - p".Look at http://msdn.microsoft.com/en-us/library/bb190764.aspx for more info.
Andrei Taptunov
Does this require the source to be present, because I don't have that.
Craig Johnston
You do need symbols (pdb files). For .NET framework assemblies you can download it from Microsoft website.
Andrei Taptunov
No. Don't have that. Only the compiled DLLs on a customer's machine.
Craig Johnston
well, then you will not see names of the local variables for example and association with source code but values for parameters and their types should be ok.
Andrei Taptunov
+1  A: 

yes use postsharp. Do the 'Getting Started' tutorial, it pretty much tells you how to do what you want. Using postsharp you may 'log' method calls in any third party party assembly.

wallismark
This appears to require the source code.
Craig Johnston
sorry I didn't notice the demo only has an example WITH source code.But you can definately do it WITHOUT source code, try this article written ages ago by the guy who wrote PostSharp...http://www.codeproject.com/KB/cs/ps-custom-attributes-2.aspxEssentially you can apply your 'aspect' with something like this in your assembly.info file:-[assembly: PerformanceCounter(AttributeTargetAssemblies = "mscorlib", AttributeTargetTypes = "System.IO.*")]
wallismark
A: 

Craig,

You can try Runtime Flow. It is a new product and can't for example catch function parameters, but its main purpose is to log calls of .NET methods made while an application is running.

Currently Runtime Flow works best with source code available, but can be configured to monitor a dll without source code.

Sergey Vlasov
I need it to catch the parameters.
Craig Johnston
Runtime Flow now supports catching the simple parameters and return values: http://blog.runtimeflow.com/2010/05/17/monitoring-function-parameters-and-return-values/
Sergey Vlasov