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...
You can use the Runtime Flow tool (developed by me, 30-day trial) to monitor which methods of an ASP.NET application are called.
DEBUG > Windows > Call Stack This option is available in almost all Visual Studio
record then my solution makes no senseThere 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.*")]