简体   繁体   中英

Enable azure diagnostics before/after deployment

I want to enable diagnostics in my web role (a web API, written in C#).

If I understand correctly, this can be done before deployment by enabling it in the cloud project, or after deployment, by configuring it using the server explorer.

I tried to do it after deployment, so what I did:

  1. Use System.Diagnostics.Trace in web API to log information and errors.
  2. kept default settings in cloud project (left 'enable diagnostics' check box unchecked).
  3. Deployed web API to Azure.
  4. Configured diagnostics using server explorer (Enable transfer of application logs).

Problem is that I don't see the trace information appearing in Application Logs if I do 'View Diagnostics Data' in server explorer.

I also tried to do it before deployment (which I would prefer), but then I get the build error: Cannot load imported module named 'Diagnostics.' after I added the import in the service definition file.

I'm probably forgetting something, but what?

Thanks!

First thing to check is if you have the 2.5 version of the DiagnosticMonitorTraceListener in your config:

  <system.diagnostics>
    <trace>
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          name="AzureDiagnostics">
          <filter type="" />
        </add>
      </listeners>
    </trace>
  </system.diagnostics>

Update 2015-01-15: Here are some additional things to check:

  1. Try adding a simple TextWriterTraceListener to the app's config file on the VM. If logs are not getting written to the trace file then you know the problem is not a WAD problem, but a generic trace problem (probably one of the two issues below). See http://msdn.microsoft.com/en-us/library/sk36c28t.aspx to setup the text listener. Make sure the element has .
  2. Make sure you are using Diagnostics.Trace.TraceXXX instead of Diagnostics.Debug.WriteXXX. The Debug statements will be removed from a Release build.
  3. Make sure the compiled code actually has the Diagnostics.Trace lines (use Reflector or ildasm to verify). Diagnostics.Trace commands are removed from the compiled binary unless you use the TRACE conditional compilation symbol. If using msbuild to build the project then this is a common problem to run into.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM