Here is the code I use in C# to output the Call Stack. In this example, I am using log4net to output each line in a log file, but it would be possible to use Writeln or another logging library:
log4net.ILog logger = log4net.LogManager.GetLogger("File");
logger.Debug("Call stack:");
StackTrace st = new StackTrace(true);
for (int i = 0; i < st.FrameCount; i++)
{
// Note that high up the call stack, there is only
// one stack frame.
StackFrame sf = st.GetFrame(i);
logger.Debug(string.Format("{0} ({1}): {2}", sf.GetFileName(), sf.GetFileLineNumber().ToString(), sf.GetMethod()));
}
application.EndRequest += new EventHandler(OnEndRequest);
logger.Debug("End of Call Stack");