Azure : Getting Trace Data to Azure Storage RRS feed

  • Question

  • User1140095199 posted

    Hi All,

    I was trying to enable Tracing for the Web Role . I intend to configure the web role to get the Trace data to the Azure Storage Tables. Storage is on Cloud.

    I have done the following coding and configuration to achieve the above. 

    1. Code in  webrole.cs  file. 
       public override bool OnStart()
                // Add Trace listener
                System.Diagnostics.Trace.Listeners.Add(new Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener());
                System.Diagnostics.Trace.AutoFlush = true;  
                // Get the default initial configuration for DiagnosticMonitor.
                DiagnosticMonitorConfiguration diagnosticConfiguration = DiagnosticMonitor.GetDefaultInitialConfiguration();
                // Enable full crash dump collection to the custom path.
                diagnosticConfiguration.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
                // Enable Windows Azure Infrastructure Logs to the storage
                diagnosticConfiguration.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
                diagnosticConfiguration.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
                // Enable Windows Azure Logs to the storage
                diagnosticConfiguration.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
                diagnosticConfiguration.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
                //// Enable Windows Event Logs to the storage
                diagnosticConfiguration.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
                diagnosticConfiguration.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
                    DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", diagnosticConfiguration);
                catch(Exception ex)
                    System.Diagnostics.Trace.WriteLine("Could not start Diagonostics" + ex.Message);
                System.Diagnostics.Trace.WriteLine("Trace writer began at " + DateTime.Now);
                Trace.TraceInformation("Microsoft.Kse.WebRole entry point called.");
                return base.OnStart();

       2.   Added the following Web.config file in the Instances in the cloud. 

      <!--Tracing Data to Azure-->
            <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
              <filter type="" />

       3.  Checked the following in the ServiceConfiguration.KSEDev.cscfg file: 

          <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=accname;AccountKey=aakey/>

      4.  Checked the following in the ServiceDefinition.csdef file:

          <Import moduleName="Diagnostics" />
          <Import moduleName="RemoteAccess" />
          <Import moduleName="RemoteForwarder" />

     Then I added some Trace.TraceInformation & Trace.TraceError using the System.Diagnostics

    Added Trace  on several places to Test if the Tracing is emitted and data moves to the Azure Storage. In Controllers and other code files.

    Unfortunately, I can only get the Trace Information from the webrole.cs and no other Trace Information is going to the Azure Storage.          

    • To Test it locally I created a demo cloud application with a web role , the above configuration is actually producing the desired result locally.
    • To make sure that the parts of code that has Tracing added is being invoked. We put break points and checked it locally.

       My actual problem is why the actual configuration is not working. The configuration in the webrole.cs should work I guess!  Am I missing a piece of information or left out something. There might be other ways to Trace information such as the XmlWriterTraceListener or TextWriterTraceListener , but I would like to use Azure Storage.  

    Thanks & Regards,

    Wednesday, March 25, 2015 5:34 AM


  • User1140095199 posted

    Hi ,

    Issue is now resolved.


    In Full IIS environment there are two processes working WaIISHost for webrole and w3wp for web application. We are just enabling Trace in webrole and not for the website. So I added the code to load Trace in the global.asax file.

    Just like that it started working in a flash!

    Hope it helps someone out there!


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 26, 2015 4:36 AM