{"id":239,"date":"2020-10-20T15:56:58","date_gmt":"2020-10-20T15:56:58","guid":{"rendered":"http:\/\/tutorials.moedesign.de\/blog\/?p=239"},"modified":"2020-10-20T15:56:58","modified_gmt":"2020-10-20T15:56:58","slug":"nlog-troubleshooting-in-asp-net-core","status":"publish","type":"post","link":"http:\/\/tutorials.moedesign.de\/blog\/nlog-troubleshooting-in-asp-net-core\/","title":{"rendered":"NLog troubleshooting in Asp.Net Core"},"content":{"rendered":"\n<p>I developed a Asp.Net Core Web API application running on a 1&amp;1 IONOS managed hosting server. For logging issues I use NLog with database target. On my local system everything worked fine and I decided to deploy it to the webserver. I called an endpoint where I excepted a log entry but nothing happened.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Problem:<br><br>Normally you can track error issues in NLog by crating a local log file. It&#8217;s configured in the nlog.config file. On a managed system you have to get the complete directory path to set it up in the config file. You can do this by injecting IHostingEnvironment in a controller and create an action GetRootPath with no parameters. In the method you enter the following code:<br><br><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">&lt;br&gt;string rootPath = _hostingEnvironment.ContentRootPath;&lt;br&gt;return Ok(rootPath);&lt;br&gt;<\/pre><br><br>Now you know the root path of your application and you can  set it in the nlog.config file to create a local internal log file.<br><\/li><li>Problem:<br><br>In my case I got an error like: Conversion failed when converting date and\/or time from character string.<br><br>The problem was the date format for the column Logged in my NLog logging table. In my nlog.config file I set it up with<br><br><pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;br&gt;&amp;lt;parameter name=&quot;@Logged&quot; layout=&quot;${date:format=dd\/MM\/yyyy HH\\:mm\\:ss.fff}&quot; \/&gt;&lt;br&gt;<\/pre><br><br>but the managed hosted SQL erver required a different date format and I solved the problem by set the format like<br><br><pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;br&gt;&amp;lt;parameter name=&quot;@Logged&quot; layout=&quot;${date:format=yyyy-MM-dd HH\\:mm\\:ss.fff}&quot; \/&gt;&lt;br&gt;<\/pre><br><br><\/li><\/ol>\n","protected":false},"excerpt":{"rendered":"<p>I developed a Asp.Net Core Web API application running on a 1&amp;1 IONOS managed hosting server. For logging issues I use NLog with database target. On my local system everything worked fine and I decided to deploy it to the webserver. I called an endpoint where I excepted a log entry but nothing happened. Problem: &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/tutorials.moedesign.de\/blog\/nlog-troubleshooting-in-asp-net-core\/\" class=\"more-link\"><span class=\"screen-reader-text\">\u201eNLog troubleshooting in Asp.Net Core\u201c <\/span>weiterlesen<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[50,53,54,52,49,55,51],"class_list":["post-239","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-asp-net-core","tag-ionos","tag-managed-hosting","tag-mvc","tag-nlog","tag-sql-server","tag-web-api"],"_links":{"self":[{"href":"http:\/\/tutorials.moedesign.de\/blog\/wp-json\/wp\/v2\/posts\/239","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/tutorials.moedesign.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/tutorials.moedesign.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/tutorials.moedesign.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/tutorials.moedesign.de\/blog\/wp-json\/wp\/v2\/comments?post=239"}],"version-history":[{"count":1,"href":"http:\/\/tutorials.moedesign.de\/blog\/wp-json\/wp\/v2\/posts\/239\/revisions"}],"predecessor-version":[{"id":240,"href":"http:\/\/tutorials.moedesign.de\/blog\/wp-json\/wp\/v2\/posts\/239\/revisions\/240"}],"wp:attachment":[{"href":"http:\/\/tutorials.moedesign.de\/blog\/wp-json\/wp\/v2\/media?parent=239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/tutorials.moedesign.de\/blog\/wp-json\/wp\/v2\/categories?post=239"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/tutorials.moedesign.de\/blog\/wp-json\/wp\/v2\/tags?post=239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}