{"id":176,"date":"2011-11-22T16:52:43","date_gmt":"2011-11-22T21:52:43","guid":{"rendered":"\/\/www.beauchamp.me\/techno\/?p=176"},"modified":"2011-11-22T16:53:05","modified_gmt":"2011-11-22T21:53:05","slug":"output-the-call-stack-in-c","status":"publish","type":"post","link":"https:\/\/www.beauchamp.me\/techno\/blog\/2011\/11\/22\/output-the-call-stack-in-c\/","title":{"rendered":"Output the call stack in C#"},"content":{"rendered":"<p>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:<\/p>\n<pre class=\"brush:csharp\">            log4net.ILog logger = log4net.LogManager.GetLogger(\"File\");\r\n            logger.Debug(\"Call stack:\");\r\n\r\n            StackTrace st = new StackTrace(true);\r\n            for (int i = 0; i &lt; st.FrameCount; i++)\r\n            {\r\n                \/\/ Note that high up the call stack, there is only\r\n                \/\/ one stack frame.\r\n                StackFrame sf = st.GetFrame(i);\r\n                logger.Debug(string.Format(\"{0} ({1}): {2}\", sf.GetFileName(), sf.GetFileLineNumber().ToString(), sf.GetMethod()));\r\n            }           \r\n\r\n            application.EndRequest += new EventHandler(OnEndRequest);\r\n\r\n            logger.Debug(\"End of Call Stack\");<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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(&#8220;File&#8221;); logger.Debug(&#8220;Call stack:&#8221;); StackTrace st = new StackTrace(true); for (int i = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[7],"tags":[],"class_list":["post-176","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"https:\/\/www.beauchamp.me\/techno\/wp-json\/wp\/v2\/posts\/176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.beauchamp.me\/techno\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.beauchamp.me\/techno\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.beauchamp.me\/techno\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.beauchamp.me\/techno\/wp-json\/wp\/v2\/comments?post=176"}],"version-history":[{"count":3,"href":"https:\/\/www.beauchamp.me\/techno\/wp-json\/wp\/v2\/posts\/176\/revisions"}],"predecessor-version":[{"id":179,"href":"https:\/\/www.beauchamp.me\/techno\/wp-json\/wp\/v2\/posts\/176\/revisions\/179"}],"wp:attachment":[{"href":"https:\/\/www.beauchamp.me\/techno\/wp-json\/wp\/v2\/media?parent=176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.beauchamp.me\/techno\/wp-json\/wp\/v2\/categories?post=176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.beauchamp.me\/techno\/wp-json\/wp\/v2\/tags?post=176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}