<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Tip #83: Did you know... You can get the name of the calling method from the stack using reflection?</title><link>http://blogs.msdn.com/webdevelopertips/archive/2009/06/23/tip-83-did-you-know-you-can-get-the-name-of-the-calling-method-from-the-stack-using-reflection.aspx</link><description>Nearly every program needs a logger to log events, errors and exceptions. Sometimes it is also useful to log the name of the method that logged the event. The easiest way to do that is to make the log method take both the calling method name and event</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Tip #83: Did you know... You can get the name of the calling method from the stack using reflection?</title><link>http://blogs.msdn.com/webdevelopertips/archive/2009/06/23/tip-83-did-you-know-you-can-get-the-name-of-the-calling-method-from-the-stack-using-reflection.aspx#9801326</link><pubDate>Wed, 24 Jun 2009 14:28:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9801326</guid><dc:creator>Marijn</dc:creator><description>&lt;p&gt;Indeed, StackTrace.GetFrame.GetMethod is nice for tose things.&lt;/p&gt;
&lt;p&gt;However, beware that an optimizing compiler might optimize away stackframes (due to inlining for example). In .NET you can add a JIT attribute ([Runtime.CompilerServices.MethodImpl(Runtime.CompilerServices.MethodImplOptions.NoInlining)]) but that only instructs the JIT to not inline. The C# compiler can not be told to not inline (but it does not seem to inline currently).&lt;/p&gt;
</description></item><item><title>re: Tip #83: Did you know... You can get the name of the calling method from the stack using reflection?</title><link>http://blogs.msdn.com/webdevelopertips/archive/2009/06/23/tip-83-did-you-know-you-can-get-the-name-of-the-calling-method-from-the-stack-using-reflection.aspx#9801516</link><pubDate>Wed, 24 Jun 2009 17:03:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9801516</guid><dc:creator>Aaron</dc:creator><description>&lt;p&gt;You beat me to this comment. I had this experience but I tried to used for something else than just logging and ended up being a nasty bug only present when compiled on release mode, so be cautious when using it as your code might be optimized by the compiler.&lt;/p&gt;
</description></item><item><title>Good for debugging </title><link>http://blogs.msdn.com/webdevelopertips/archive/2009/06/23/tip-83-did-you-know-you-can-get-the-name-of-the-calling-method-from-the-stack-using-reflection.aspx#9801611</link><pubDate>Wed, 24 Jun 2009 18:02:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9801611</guid><dc:creator>Greg</dc:creator><description>&lt;p&gt;I've used this for debugging/logging but avoided it for non-debug code. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;It still doesn't beat printable to end user message numbers in error/log messages as you can text search for them right away to get the source line that printed the message.&lt;/p&gt;
</description></item><item><title>re: Tip #83: Did you know... You can get the name of the calling method from the stack using reflection?</title><link>http://blogs.msdn.com/webdevelopertips/archive/2009/06/23/tip-83-did-you-know-you-can-get-the-name-of-the-calling-method-from-the-stack-using-reflection.aspx#9801758</link><pubDate>Wed, 24 Jun 2009 20:05:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9801758</guid><dc:creator>Casey Barton</dc:creator><description>&lt;p&gt;I just instinctively reference log4net, even for simple little on-off tools. You can log calling method amongst a hundred other attributes, just by configuring a format string.&lt;/p&gt;
</description></item><item><title>re: Tip #83: Did you know... You can get the name of the calling method from the stack using reflection?</title><link>http://blogs.msdn.com/webdevelopertips/archive/2009/06/23/tip-83-did-you-know-you-can-get-the-name-of-the-calling-method-from-the-stack-using-reflection.aspx#9803466</link><pubDate>Thu, 25 Jun 2009 15:26:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9803466</guid><dc:creator>Óscar González</dc:creator><description>&lt;p&gt;How can you get the called method from the constructor?&lt;/p&gt;
</description></item><item><title>re: Tip #83: Did you know... You can get the name of the calling method from the stack using reflection?</title><link>http://blogs.msdn.com/webdevelopertips/archive/2009/06/23/tip-83-did-you-know-you-can-get-the-name-of-the-calling-method-from-the-stack-using-reflection.aspx#9806049</link><pubDate>Sat, 27 Jun 2009 01:27:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9806049</guid><dc:creator>Nicholas Piasecki</dc:creator><description>&lt;p&gt;Referencing Aaron and Marijn, I got burned by this too. It's prone to error and I recommend not using it, unless you're positive it will only run in Debug builds.&lt;/p&gt;
</description></item></channel></rss>