Enable Azure Website Application Diagnostics

白昼怎懂夜的黑 提交于 2019-12-07 22:13:12

问题


I have a Windows Azure Website (built with ASP.NET Web Pages), and in the configuration have enabled "Application Diagnostics" for both Blob storage and file storage:

I've then added some Trace statements to a Razor page to test it out

@{
    System.Diagnostics.Trace.TraceInformation("INFORMATION");
    System.Diagnostics.Trace.TraceWarning("WARNING");
    System.Diagnostics.Trace.TraceError("ERROR");
}

However, this results in no logs at all, either in the file system or the blob. For good measure I attempted to add various settings to my web.config file (shown below), although from the documentation I read, it doesn't seem as though this should be necessary. But it makes no difference - I still see no diagnostic logs in the file system or the blob.

  <system.web>
    <compilation debug="true" targetFramework="4.5">
      <assemblies>
        <add assembly="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>
    <trace enabled="true"/>
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.diagnostics>
    <trace>
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
     name="AzureDiagnostics">
        </add>
        <add name="WebPageTraceListener"
             type="System.Web.WebPageTraceListener, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      </listeners>
    </trace>
  </system.diagnostics>

Is there anything else I need to configure that I've missed? Could it be that this simply doesn't work at all for ASP.NET Web Pages projects?


回答1:


To enable tracing from a razor page add the following to your web.config: <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" compilerOptions="/define:TRACE" warningLevel="1" /> </compilers> </system.codedom>

Source: http://blogs.msdn.com/b/webdev/archive/2013/07/16/tracing-in-asp-net-mvc-razor-views.aspx

Note that tracing from your cs files should work without any changes to web.config.



来源:https://stackoverflow.com/questions/28157442/enable-azure-website-application-diagnostics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!