0

Is there any built-in option in visual studio 2013, or an add-on that could record which methods of ASP.NET application are called at some time and in which sequence?

Example:

request();
processRequest();
sendResponse();

etc...

3 Answers 3

2

You can use the Runtime Flow tool (developed by me, 30-day trial) to monitor which methods of an ASP.NET application are called.

Sign up to request clarification or add additional context in comments.

2 Comments

nice product :) a bit expensive for my pockets, but very interesting
dotnetmonitor.vlasovstudio.com/2012/01/19/… tried this, and it doesnt work.. It starts but there is nothing in my runtime flow window... using vs 2013 proffesional
1
  1. Put a debug point of the method you wanna debug
  2. Go to DEBUG > Windows > Call Stack
  3. This will list all the methods that were called before this method.

This option is available in almost all Visual Studio

2 Comments

seems the OP would record, not simply show, the execution of the methods
@Infer-On: You are right. If user wants to record then my solution makes no sense
1

There is not a built-in method to record method executions, what you can do, using Diagnostic and Reflection api, is something like this:

using System.Diagnostics;
using System.Reflection;

[STAThread]
static void Main(string[] args)
{
    MyMethodName();
}

private static void WhatsMyName()
{
    StackFrame stackFrame = new StackFrame();
    MethodBase methodBase = stackFrame.GetMethod();
    Console.WriteLine(methodBase.Name );
    CalleedMethodName();
}

private static void CalleedMethodName()
{
    StackTrace stackTrace = new StackTrace();
    StackFrame stackFrame = stackTrace.GetFrame(1);
    MethodBase methodBase = stackFrame.GetMethod();
    Console.WriteLine( " Parent Method Name {0} ", methodBase.Name ); 
}

If you can use PostSharp you can write a Log Aspect like this:

[Serializable]
public class LogAspect: OnMethodBoundaryAspect {

public override void OnEntry(MethodExecutionArgs args) {
    Console.WriteLine("{0}: {1}", args.Method.Name, DateTime.Now);
}

public override void OnSuccess(MethodExecutionArgs args) {
    Console.WriteLine("{0} complete: {1}",
    args.Method.Name, DateTime.Now);
}

}

and decorate every methods you would log,

public class MyClass {
[LogAspect]
public MyClass() { }
[LogAspect]
public void Method1() { }
[LogAspect]
public void Method2() { Method3(); }
[LogAspect]
private void Method3() { }
}

or else decorate enterely class:

[LogAspect]
public class MyClass {

    public MyClass() { }

    public void Method1() { }

    public void Method2() { Method3(); }

    private void Method3() { }
    }

EDIT

You can also apply PostSharp aspect at namespace level

Applying an aspect to all types in a namespace.

Even though we don't have to apply an aspect to all methods in all classes in our application, adding the aspect attribute to every class could still be an overwhelming task. If we want to apply our aspect in a broad stroke we can make use of PostSharp's MulticastAttribute.

The MulticastAttribute is a special attribute that will apply other attributes throughout your codebase. Here's how we would use it.

Open the AssemblyInfo.cs, or create a new file GlobalAspects.cs if you prefer to keep things separate (the name of this file does not matter). Add an [assembly:] attribute that references the aspect you want applied. Add the AttributeTargetTypes property to the aspects's constructor and define the namespace that you would like the aspect applied to. [assembly: OurLoggingAspect(AttributeTargetTypes= "OurCompany.OurApplication.Controllers.*")]

4 Comments

Is there maybe some 3rd party tool? I found MSE but it is only for exe apps... And I have too many methods in project to add LogAspect to every method...
RestSharp weaving can be applied also at assembly level, and a namespace level, in multicast
This is a great answer, but I cant use console.write or as in postsharp tracelistener in Main(), because I dont have Main in asp.net app
obviously I assume you would use NLOG or other Loggin frameworks, my example is only a generic example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.