我可以在OWIN中启用跟踪吗?

Jam*_*mie 14 asp.net-mvc trace owin

我在OWIN的某个地方遇到环境问题,我希望得到一些有关正在发生的事情的信息.我已经读过,我可以启用跟踪但无法找到有关如何执行此操作的详细信息.

我已将以下内容添加到我的web.config中但没有快乐.这可能吗?

<!-- 1. Enable the switch here. Without this, you get nothing. By default, Katana has "new SourceSwitch("Microsoft.Owin")" at the root level. -->
<switches>
  <add name="Microsoft.Owin" value="Verbose" />
</switches>

<!-- 2. Add your shared listeners. -->
<trace autoflush="true" />
<sharedListeners>
  <add name="file" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\traces\Microsoft.OWIN.trace.log" />
  <add name="console" type="System.Diagnostics.ConsoleTraceListener" />
</sharedListeners>

<sources>
  <!-- "Microsoft.Owin" is the SourceSwitch name katana is using at the rootlevel. By enabling this, we are enabling all sub level traces by the components (if we don't change the default trace settings). -->
  <source name="Microsoft.Owin">
    <listeners>
      <add name="file" />
      <add name="console" />
    </listeners>
  </source>
</sources>
Run Code Online (Sandbox Code Playgroud)

小智 5

不能100%地确定这可以解决您的问题,但是我们可以通过以下配置来解决。以下行略有不同:

<source name="Microsoft.Owin" switchName="Microsoft.Owin" switchType="System.Diagnostics.SourceSwitch">
Run Code Online (Sandbox Code Playgroud)

请注意,<source>标记中包含switchName(和switchType)属性,您的示例中缺少该属性。我认为该指令将TraceSource与Switch链接在一起并完成整个工作。

在本例中,我们将跟踪侦听器用于Azure网站(和Web作业)。

 <system.diagnostics>
    <sharedListeners>
      <add name="AzureTableTraceListener" type="Microsoft.WindowsAzure.WebSites.Diagnostics.AzureTableTraceListener, Microsoft.WindowsAzure.WebSites.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      <add name="AzureBlobTraceListener" type="Microsoft.WindowsAzure.WebSites.Diagnostics.AzureBlobTraceListener, Microsoft.WindowsAzure.WebSites.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      <add name="AzureDriveTraceListener" type="Microsoft.WindowsAzure.WebSites.Diagnostics.AzureDriveTraceListener, Microsoft.WindowsAzure.WebSites.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </sharedListeners>
    <sources>
      <source name="Microsoft.Owin" switchName="Microsoft.Owin" switchType="System.Diagnostics.SourceSwitch">
        <listeners>
          <add name="AzureTableTraceListener"/>
          <add name="AzureDriveTraceListener"/>
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="Microsoft.Owin" value="All" />
    </switches>
    <trace autoflush="true" indentsize="4" />
  </system.diagnostics>
Run Code Online (Sandbox Code Playgroud)