3

I'm trying to get nlog working with the Azure webapp Log Stream.

The logs do appear if I don't use nlog, and just use System.Diagnostics.Trace.WriteLine.

However, if I use the Trace type in my nlog.config, it doesn't show the trace logs ...

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <targets>
        <target xsi:type="Trace" name="trace" layout="${message}" />
    </targets>

    <rules>
        <logger name="*" minlevel="Trace" writeTo="trace" />
    </rules>
</nlog>

I can't see anything that I'm doing differently from the accepted answer here ...

How to integrate NLog to write log to Azure Streaming log

Note that I cut down that nlog.config file to just show the trace - but I do normally also have a File target type - I've tried with and without this.

I've logged onto the deployed Azure website, and the nlog config file had been uploaded successfully. I'm deploying using the Github deployment.

I have the logging set in Azure to just use the file system logging, and I have that set to verbose.

Any ideas?

Community
  • 1
  • 1
Dan
  • 5,692
  • 3
  • 35
  • 66

2 Answers2

5

It turns out that when Visual Studio enabled Application Insights (a recent thing I added to the project), it had inserted an nlog config section into my web.config. This had then meant that my nlog.config file wasn't being used at all. I've fixed it by removing that nlog config section from my web.config, and copying the Application Insights target into my nlog.config file instead. The 'Trace' target type now works as expected and is appearing in the Azure Streaming Logs.

Dan
  • 5,692
  • 3
  • 35
  • 66
2

The NLog-Trace-Target only performs Trace.WriteLine for Debug-Level Log-Events.

Maybe try the custom MyTraceTarget shown here:

https://github.com/NLog/NLog/issues/1968

Update NLog ver. 4.5 adds the new setting rawWrite for the NLog Trace-target so it always performs WriteLine independent of LogLevel. See also https://github.com/NLog/NLog/wiki/Trace-target

Rolf Kristensen
  • 17,785
  • 1
  • 51
  • 70
  • Thanks for this. Your suggestion about the custom target led me down the right path, as the custom target wasn't working either, so I ended up looking at the LogManger.Configuration in the debugger, and that showed me the actual issue. Upvoted :) – Dan Feb 27 '17 at 20:06