Trace messages from Website not appearing in Azure Diagnostics

1.2k views Asked by At

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...

3

There are 3 answers

1
Alasdair Ross On BEST ANSWER

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.

1
Rick Rainey On

You don't need the reference to Microsoft.WindowsAzure.Diagnostics in your project. That is for Cloud Services and the article you referenced does not mention it since it is for Azure Web Apps (formerly Websites).

Assuming you are using an Azure Web App (not a cloud service web role), then you have to use the current Azure Management portal at https://manage.windowsazure.com if you want to configure your web app to store application diagnostics to an Azure Storage Table or Azure Storage Blob Container. In the configure page for the web app, your configuration should look like this for a table storage.
enter image description here

(Currently, the preview portal at https://portal.azure.com only lets you configure application diagnostics logging using the web app's file system)

0
Winks On

For anyone who still encounters this problem, besides for the excellent answers given on this page (enable tracing on azure, and making sure TRACE is set to true in your build), make sure you actually flush the traces!

In your code you need something like this:

System.Diagnostics.Trace.TraceError("Can you see me?");
System.Diagnostics.Trace.Flush();

Or

System.Diagnostics.Trace.AutoFlush = true;
System.Diagnostics.Trace.TraceError("Can you see me?");