{"id":23,"date":"2018-03-01T15:20:00","date_gmt":"2018-03-01T21:20:00","guid":{"rendered":""},"modified":"2023-07-27T12:14:53","modified_gmt":"2023-07-27T17:14:53","slug":"logging-methodbase-getcurrentmethod-name-results-in-movenext","status":"publish","type":"post","link":"https:\/\/www.chrystalsander.com\/blog\/?p=23","title":{"rendered":"Logging MethodBase.GetCurrentMethod().Name Results in &#8220;MoveNext&#8221;"},"content":{"rendered":"<p>Using log4net, the following code example has always (that I&#8217;ve paid attention to) successfully written the method name to the log:<\/p>\n<p>CODE:<br \/>\n<span style=\"color: #38761d; font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace; font-size: x-small;\"><b>catch (Exception ex)<\/b><\/span><br \/>\n<span style=\"color: #38761d; font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace; font-size: x-small;\"><b>{<\/b><\/span><br \/>\n<span style=\"color: #38761d; font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace; font-size: x-small;\"><b>&nbsp; globalMgr.Logger.Debug($&#8221;Exception thrown in&nbsp; {MethodBase.GetCurrentMethod().Name} {ex.Message}&nbsp; {ex.StackTrace} &#8220;);<\/b><\/span><br \/>\n<span style=\"color: #38761d; font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace; font-size: x-small;\"><b>&nbsp; return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);<\/b><\/span><br \/>\n<span style=\"color: #38761d; font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace; font-size: x-small;\"><b><\/b><\/span><\/p>\n<p>LOG TEXT:<br \/>\n<span style=\"color: #38761d; font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace; font-size: x-small;\"><b>Starting HttpClient in GetStoreData()<\/b><\/span><\/p>\n<p>Lately, however, the method base is logged as &#8220;MoveNext.&#8221;<\/p>\n<p>LOG TEXT:<br \/>\n<span style=\"color: #38761d; font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace; font-size: x-small;\"><b>Starting HttpClient in MoveNext<\/b><\/span><\/p>\n<p>The reason for this is that I&#8217;m placing the GetCurrentMethod call inside an async method.&nbsp; &nbsp;Therefore, the final method that the code lives is indeed in &#8220;MoveNext.&#8221;&nbsp; <\/p>\n<p>If I don&#8217;t get back with a solution soon enough, hard-code your method names into the logging but do not tell anyone I told you to do such a thing.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using log4net, the following code example has always (that I&#8217;ve paid attention to) successfully written the method name to the log: CODE: catch (Exception ex) { &nbsp; globalMgr.Logger.Debug($&#8221;Exception thrown in&nbsp; {MethodBase.GetCurrentMethod().Name} {ex.Message}&nbsp; {ex.StackTrace} &#8220;); &nbsp; return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); LOG TEXT: Starting HttpClient in GetStoreData() Lately, however, the method base is logged as &#8220;MoveNext.&#8221; LOG TEXT: &hellip; <a href=\"https:\/\/www.chrystalsander.com\/blog\/?p=23\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Logging MethodBase.GetCurrentMethod().Name Results in &#8220;MoveNext&#8221;&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,92],"tags":[42],"_links":{"self":[{"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/23"}],"collection":[{"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=23"}],"version-history":[{"count":1,"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/23\/revisions"}],"predecessor-version":[{"id":156,"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/23\/revisions\/156"}],"wp:attachment":[{"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}