0

I have a pretty simple WCF service set up to run in an Azure web role. It's not working quite right (expectedly), but I need to gather trace diagnostics to debug successfully. Could someone identify where I've gone wrong?

Here is my web.config for the web role:

<?xml version="1.0"?>
<configuration>
  <configSections>
  </configSections>
  <!--  To collect diagnostic traces, uncomment the section below or merge with existing system.diagnostics section.
        To persist the traces to storage, update the DiagnosticsConnectionString setting with your storage credentials.
        To avoid performance degradation, remember to disable tracing on production deployments. -->
  <system.diagnostics>
    <sources>
      <source propagateActivity="true" name="System.ServiceModel" switchValue="Verbose,ActivityTracing">
        <listeners>
          <add name="AzureLocalStorage">
            <filter type="" />
          </add>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging" switchValue="Verbose">
        <listeners>
          <add name="AzureLocalStorage">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>
    <trace>
        <listeners>
            <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="AzureDiagnostics">
                <filter type="" />
            </add>
        </listeners>
    </trace>
    <sharedListeners>
        <add name="AzureLocalStorage" type="MyApp.Svc.AzureLocalStorageTraceListener, MyApp.Svc" />
    </sharedListeners>
  </system.diagnostics>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <customErrors mode="Off" />
  </system.web>
  <system.serviceModel>
    <diagnostics>
      <messageLogging logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
      <endToEndTracing activityTracing="true" messageFlowTracing="true" />
    </diagnostics>
    <services>
      <service name="MyApp.Svc.Tracker">
        <endpoint address="" behaviorConfiguration="restJsonBehavior"
          binding="webHttpBinding" bindingConfiguration="" name="restEndpoint"
          contract="Cogent.TimeTracker.Azure.Svc.ITracker" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="restJsonBehavior">
          <webHttp helpEnabled="true" defaultOutgoingResponseFormat="Json" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <rewrite>
        <rules>
            <rule name="TrackerService" stopProcessing="true">
                <match url="^tracker/(.*)$"/>
                <action type="Rewrite" url="Tracker.svc/{R:1}"/>
            </rule>
        </rules>
    </rewrite>
  </system.webServer>
</configuration>

I just keep staring at this, thinking to myself: "I can't find anything wrong with this!". Here's my ServiceDefinition.csdef:

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="MyApp" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WebRole name="MyApp.Svc" vmsize="Small">
    <Sites>
      <Site name="Web">
        <Bindings>
          <Binding name="Endpoint1" endpointName="Endpoint1" />
        </Bindings>
      </Site>
    </Sites>
    <Endpoints>
      <InputEndpoint name="Endpoint1" protocol="http" port="80" />
    </Endpoints>
    <Imports>
      <Import moduleName="Diagnostics" />
      <Import moduleName="Connect" />
    </Imports>
    <LocalResources>
      <LocalStorage name="MyApp.Svc.svclog" sizeInMB="1000" cleanOnRoleRecycle="true" />
    </LocalResources>
    <Startup>
      <Task commandLine="installStuff.cmd" executionContext="elevated">
        <Environment>
          <Variable name="EMULATED">
            <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
          </Variable>
        </Environment>
      </Task>
    </Startup>
  </WebRole>
</ServiceDefinition>

and finally, my ServiceConfiguration.Cloud.cscfg:

<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="MyApp" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="1" osVersion="*">
  <Role name="MyApp.Svc">
    <Instances count="1" />
    <ConfigurationSettings>
      <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=myaccountname;AccountKey=myaccountkey" />
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.ActivationToken" value="myactivationtoken" />
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.Refresh" value="" />
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.WaitForConnectivity" value="" />
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.Upgrade" value="" />
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.EnableDomainJoin" value="" />
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainFQDN" value="" />
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainControllerFQDN" value="" />
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainAccountName" value="" />
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainPassword" value="" />
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainOU" value="" />
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.Administrators" value="" />
      <Setting name="Microsoft.WindowsAzure.Plugins.Connect.DomainSiteName" value="" />
    </ConfigurationSettings>
  </Role>
</ServiceConfiguration>

Update: and also my WebRole.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Diagnostics;
using Microsoft.WindowsAzure.ServiceRuntime;
using System.Diagnostics;

namespace MyApp.Svc
{
    public class WebRole : RoleEntryPoint
    {
        public override bool OnStart()
        {
            // To enable the AzureLocalStorageTraceListner, uncomment relevent section in the web.config  
            DiagnosticMonitorConfiguration diagnosticConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();
            diagnosticConfig.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
            diagnosticConfig.Directories.DataSources.Add(AzureLocalStorageTraceListener.GetLogDirectory());
            DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", diagnosticConfig);
            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

            Trace.WriteLine("MyApp.Svc started", "Information");
            return base.OnStart();
        }
    }
}
Ben Collins
  • 20,538
  • 18
  • 127
  • 187

2 Answers2

1

It seems we cannot spot any major issue in the configuration. But please make sure you’re using the correct type:

type="MyApp.Svc.AzureLocalStorageTraceListener, MyApp.Svc"

Check if it is correct. Actually you can also remove the type. I would like to suggest you to check http://blogs.msdn.com/b/myazureworld/archive/2011/07/20/wcf-tracing-in-windows-azure-sdk-1-3-or-higher.aspx for a sample.

If it doesn’t help, please try to use remote desktop to connect to the server to see whether there is any traces in local storage.

Best Regards,

Ming Xu.

Ming Xu - MSFT
  • 2,116
  • 1
  • 11
  • 13
0

Actually, I think it turns out that this configuration was working fine, I just wasn't being patient enough for the DiagnosticMonitor to write out to the blob.

Ben Collins
  • 20,538
  • 18
  • 127
  • 187