2013-03-04 52 views
5

在我的web.config我有以下設置:爲什麼Visual Studio會抱怨我的web.config跟蹤偵聽器配置?

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

這是一樣的,如MSDN例如here

<system.diagnostics> 
    <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> 

然而,Visual Studio會強調內部type屬性<filter type=""當我在那裏移動鼠標時,它說the 'type' attribute is not allowed。如果我嘗試使用智能感知來找到允許的內容,它提供了lockItem,lockElements,lockAttributes,lockAllElementsExceptlockAllAttributesExcept

爲什麼Visual Studio不像type裏面filter

+0

代碼是否編譯,並且它是否工作?唯一的問題是Visual Studio抱怨? – DOK 2013-03-04 13:45:13

+0

@DOC:它看起來很有用,但我不太明白「類型」應該做什麼以及爲什麼VS抱怨。 – sharptooth 2013-03-04 13:48:20

+0

您是否運行ReSharper?那裏有一個錯誤,他們還沒有設法修復。 – 2013-03-04 14:37:52

回答

8

Visual Studio使用模式驗證配置文件中的XML。在這種情況下,它看不到爲模式中的過濾器元素定義的類型屬性。這可能只是架構中的一個監督/錯誤,因爲過濾器配置的使用明顯需要它,如果沒有它,將無法正常工作。這不是Windows Azure特有的。

如果打開app.config/web.config文件並檢查屬性窗口,您將看到Schemas屬性。這些都是用來驗證配置文件的模式,有幾個。這裏感興趣的模式是DotNetConfig.xsd(在我的機器上,使用VS 2012在C:\ Program Files(x86)\ Microsoft Visual Studio 11.0 \ xml \ Schemas \ 1033 \ DotNetConfig.xsd下)。如果您熟悉XSD,則可以將其打開,如果深入查看元素定義(configuration/system.diagnostics/trace/listeners/ListenerElement/filter),則會看到沒有指示任何類型元素。但是,如果您查看共享偵聽器(配置/ system.diagnostics/sharedListeners/ListenerElement/filter)下的過濾器元素,則屬性類型存在並且是必需的。

如果你使用了下面的配置,你將不會在VS中看到下劃線,因爲預期在共享偵聽器部分的過濾器下輸入類型。我會再次指出這裏的下劃線並不重要,它只是VS說它不認爲你應該把type屬性放在過濾器下面,但是如果你想要在trace中定義過濾器,這顯然是必需的聽衆,只是模式中的一個錯誤。我不會爲此擔心。

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

     </sharedListeners> 
     <trace> 
      <listeners> 
       <add name="AzureDiagnostics" /> 
      </listeners> 
     </trace> 
    </system.diagnostics> 
相關問題