Configure the TraceListener in an Azure Application
Updated: August 18, 2014
When using Trace, Debug and TraceSource, you must have a mechanism for collecting and recording the messages that are sent. Trace messages are received by listeners. The purpose of a listener is to collect, store, and route tracing messages. Listeners direct the tracing output to an appropriate target, such as a log, window, or text file. For Windows Azure Diagnostics, the DiagnosticMonitorTraceListener class is used. Before you complete the following procedure, you must initialize the Windows Azure diagnostic monitor. To do this, see Enabling Diagnostics in Windows Azure.
|If you use the templates that are provided by Visual Studio, the configuration of the listener has been added for you.|
Open the web.config or app.config file for your role.
Add the following code to the file:
<system.diagnostics> <trace> <listeners> <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=22.214.171.124, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics"> <filter type="" /> </add> </listeners> </trace> </system.diagnostics>
Save the file.
For more information about listeners, see Trace Listeners.
After you complete the steps to add the listener, you can add trace statements to your code. To do this, see Use Trace Messages in an Azure Application.