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>


Sharepoint AddIn: Read items from a list by code

I started developing a Sharepoint Provider Hosted AddIn a few days ago. In this AddIn I want to read items from a list and display them in a special way. I found nearly all needed information on the Microsoft Docs. But one important information isn’t mentioned or I didn’t get it: You have to give permissions to the app otherwise you can read the list title but any item.

For giving the app permissions go to the AppManifest.xml and add a area List with the permission FullControl.

Build your project again and start it. You’ll see a Sharepoint page where you are asked if you trust your app and where you can define in a dropdown which list should be fully controlled by the app. Afterwords your app will get all items of the list if needed.