3

I would like to implement NLog in my ASP.NET Core project that is going to be deployed to Azure.

I am using the code suggested in https://github.com/damienbod/AspNetCoreNlog

How do I modify the following lines to allow it to be used in Azure?

In nlog.config:

internalLogFile="C:\git\damienbod\AspNetCoreNlog\Logs\internal-nlog.txt"

In the Startup class:

LogManager.Configuration.Variables["configDir"] = "C:\\git\\damienbod\\AspNetCoreNlog\\Logs";
Jonas Arcangel
  • 2,085
  • 11
  • 55
  • 85
  • I found this that looks like it may be what you are looking for https://damienbod.com/2016/08/17/asp-net-core-logging-with-nlog-and-microsoft-sql-server/ – Jonathan Aug 25 '17 at 20:53
  • 1
    That page also does not say how to modify all references to "C:\git\..." so that it will work in Azure. – Jonas Arcangel Aug 25 '17 at 21:10
  • Can you write to file in azure? – Julian Aug 26 '17 at 16:21
  • Yes, answered here. https://stackoverflow.com/questions/12964129/can-i-write-to-file-system-on-azure-web-site I suppose I can use Server.MapPath for the Startup class change. How do I do that in the config file? – Jonas Arcangel Aug 26 '17 at 18:49
  • Found the answer. http://intellitect.com/creating-an-nlog-wrapper-that-logs-to-azure-table-storage/ – Jonas Arcangel Aug 26 '17 at 18:53

1 Answers1

1

In this article: An internal log file is also defined, so that if something is wrong with the logging configuration, you can find out why. we can know the internal log file is saved on disk via configure internalLogFile="C:\git\damienbod\AspNetCoreNlog\Logs\internal-nlog.txt, and based on my test, we can modify it to save internal log file on Azure web app server.

I configure it to:

internalLogFile="D:\home\site\AspNetCoreNlog\Logs\internal-nlog.txt"

and

LogManager.Configuration.Variables["configDir"] = "D:\\home\\site\\AspNetCoreNlog\\Logs";

The app works fine on Azure web app service, and I can access AspNetCoreNlog folder and internal log file via Kudu console.

enter image description here

Fei Han
  • 26,415
  • 1
  • 30
  • 41