NLog troubleshooting in Asp.Net Core

I developed a Asp.Net Core Web API application running on a 1&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.

  1. Problem:

    Normally you can track error issues in NLog by crating a local log file. It’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>string rootPath = _hostingEnvironment.ContentRootPath;<br>return Ok(rootPath);<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.
  2. Problem:

    In my case I got an error like: Conversion failed when converting date and/or time from character string.

    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>&lt;parameter name="@Logged" layout="${date:format=dd/MM/yyyy HH\:mm\:ss.fff}" /><br>


    but the managed hosted SQL erver required a different date format and I solved the problem by set the format like

    <br>&lt;parameter name="@Logged" layout="${date:format=yyyy-MM-dd HH\:mm\:ss.fff}" /><br>