visual-studio-2010 - 为什么 Visual Studio 提示我的 web.config 跟踪监听器配置?

标签 visual-studio-2010 iis azure web-config azure-diagnostics

在我的 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 。如果我尝试使用 IntelliSense 来查找允许的内容,它会提供 lockItem , lockElements , lockAttributes , lockAllElementsExceptlockAllAttributesExcept .

为什么 Visual Studio 不喜欢 type里面filter

最佳答案

Visual Studio 使用架构来验证配置文件中的 XML。在这种情况下,它看不到为架构中的过滤器元素定义的类型属性。这可能只是模式中的一个疏忽/错误,因为过滤器配置的使用显然需要它,并且没有它就无法工作。这根本不是 Windows Azure 特有的。

如果您打开 app.config/web.config 文件并检查属性窗口,您将看到 Schemas 属性。这些是用于验证配置文件的所有架构,并且有多个。这里感兴趣的模式是 DotNetConfig.xsd (在我的机器上,它位于 C:\Program Files (x86)\Microsoft Visual Studio 11.0\xml\Schemas\1033\DotNetConfig.xsd 下,使用 VS 2012)。如果您熟悉 XSD,则可以破解此漏洞,如果深入查看元素定义 (configuration/system.diagnostics/trace/listeners/ListenerElement/filter),您将看到没有指示任何类型元素。但是,如果您查看共享监听器 (configuration/system.diagnostics/sharedListeners/ListenerElement/filter) 下的过滤器元素,属性类型就在那里并且是必需的。

如果您使用下面的配置,您将不会在 VS 中看到下划线,因为共享监听器部分的过滤器下需要类型。我再次指出,这里的下划线确实不重要,只是 VS 说它不认为你应该将 type 属性放在过滤器下,但如果你想在跟踪下定义过滤器,那么它显然是必需的听众,这只是架构中的一个错误。我不会担心这个。

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

关于visual-studio-2010 - 为什么 Visual Studio 提示我的 web.config 跟踪监听器配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15202945/

相关文章:

Azure ARM 模板

c# - 如何从 Web 应用程序调试 C#/.NET 解决方案中的 Web 服务

c# - 配置管理器未保存在 app.config 中

performance - 我可以在一个 Windows Server 2008 机器中打开的最大 HTTP 连接数是多少?

c# - 如何在 ASP.NET 中路由 "pretty"动态 URL(没有查询字符串)?

azure - 无法将 VHD 上传到 Azure

c# - .NET 4.0 项目如何引用使用 v2.0.50727 运行时的程序集?

visual-studio-2010 - Visual Studio 2010 : Windows Installer using msiexec. exe 返回 MSI 错误 2727

c# - Web应用中如何获取Web请求域用户信息

c# - 尝试使用环境凭据连接到 Azure 不起作用