Azure / WCF诊断似乎不起作用,现在我已经看了太久了。怎么了?

时间:2012-05-15 16:48:05

标签: wcf azure system.diagnostics

我有一个非常简单的WCF服务,可以在Azure Web角色中运行。它不是很正常(预期),但我需要收集跟踪诊断以成功调试。有人可以找出我出错的地方吗?

以下是我对web角色的web.config:

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

我只是一直盯着这个,对自己说:“我找不到任何错误!”。这是我的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>

最后,我的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>

更新:以及我的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();
        }
    }
}

2 个答案:

答案 0 :(得分:1)

我们似乎无法发现配置中的任何重大问题。但请确保您使用的是正确的类型:

type =“MyApp.Svc.AzureLocalStorageTraceListener,MyApp.Svc”

检查是否正确。实际上你也可以删除类型。我建议您查看http://blogs.msdn.com/b/myazureworld/archive/2011/07/20/wcf-tracing-in-windows-azure-sdk-1-3-or-higher.aspx样本。

如果没有帮助,请尝试使用远程桌面连接到服务器,以查看本地存储中是否有任何痕迹。

最诚挚的问候,

徐明。

答案 1 :(得分:0)

实际上,我认为事实证明这种配置工作正常,我只是没有耐心等待DiagnosticMonitor写出blob。