Search code examples
azureazure-diagnostics

Trace messages from Website not appearing in Azure Diagnostics


I have an API deployed as an Azure Website (not a worker role). The code for the site has Trace statements dotted through it that I would like to capture in an Azure Table via the Azure Diagnostics.

I'm using Trace.TraceError, Trace.TraceInformation, etc.

I've followed the instructions here, which essentially say that all that is required is to flick the switch in the management portal and set a location for Application Diagnostics: https://azure.microsoft.com/en-us/documentation/articles/web-sites-enable-diagnostic-log/

I have ensured that the Microsoft.WindowsAzure.Diagnostics reference is added to the project, and I have also tried adding the following to the Web.config (even though the instructions don't say this is necessary):

<system.diagnostics>
  <trace autoflush="true" indentsize="4" >
    <listeners>
      <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics" />
    </listeners>
  </trace>
</system.diagnostics>

Despite this, the only output I get to the Azure Blob and/or Table (that I specified in the portal) is the following:

24/06/2015 14:02:49 AlasdairOTCDev  Verbose SnapshotHelper::RestoreSnapshotInternal SUCCESS - process   11284   -1
24/06/2015 14:02:48 AlasdairOTCDev  Verbose SnapshotHelper::RestoreSnapshotInternal SUCCESS - File.Copy 11284   -1

Trace levels are set to Verbose in the portal.

What am I doing wrong, and how can I debug this?

Many thanks for any assistance that can be provided as I'm rapidly running out of hair to pull out...


Solution

  • It turns out the root of the problem was with our build.

    There was an issue where our build script was not compiling the TRACE symbol. Builds compiled locally did include this (which is why it all appeared to work locally) but when we built and deployed to Azure it was being missed out.

    Without the TRACE symbol, none of the logging statements were activated.