Unable to Write Logs into Azure with Nlog

Viewed 274

I am Working on a DotNET core application and trying to implement Nlogs into Azure App service. While working on Local machine/Visual Studio, I am successfully able to generate Nlogs. However, when I publish the application to deploy on Azure Cloud, Nlogs do not generate at the Specified location.

This is the configuration which I did to publish the Nlog:- Release Configuration

After Deploying the application to cloud app service the configuration looks like:- Application settings

I do not receive any error and application works fine, Though I don't see any logs generated on app service.

1 Answers

You can activate log stream from log-files, so it will monitor any files ending in .txt or .log, that are stored in the HOME-folder. Then you can use a File-target:

<?xml version="1.0" encoding="utf-8"?>
<nlog>
   <targets async="true">
      <target name="logfile" xsi:type="File" filename="${environment:HOME:cached=true}/logfiles/application/app-${shortdate}-${processid}.txt" />
   </targets>
   <rules>
      <logger name="*" minlevel="Info" writeTo="logfile" />
   </rules>
</nlog>

See also: https://github.com/NLog/NLog.Extensions.Logging/wiki/NLog-cloud-logging-with-Azure-function-or-AWS-lambda#writing-to-azure-diagnostics-log-stream

Related