Azure 应用程序日志记录不适用于我的 Web 应用程序

Kei*_*ith 5 c# system.diagnostics azure asp.net-core-mvc azure-web-app-service

我在让 Azure 应用程序日志记录与我的 Web 应用程序配合使用时遇到问题。我可以成功发布并使用我的网络应用程序。然而,当我查看日志时,“应用程序”文件夹是空的。我可以成功地在 stdout.log 文件中看到我写入控制台的消息...但应用程序文件夹中从来没有任何内容。

至于我所尝试的,我已按照此处概述的步骤进行操作。看起来很简单。配置 Azure 以打开应用程序日志记录,在代码中编写跟踪命令,并且内容应写入日志中的应用程序文件夹。我还尝试将应用程序日志记录 (Blob) 设置为打开,但我也没有看到其中写入任何内容。

下面是我在 Azure 中配置的屏幕截图:

天蓝色截图

这是我用代码写入 Trace 的示例:

public class HomeController : Controller
{
    public IActionResult Index()
    {
        Trace.TraceInformation("At Home");
        return View();
    }
}
Run Code Online (Sandbox Code Playgroud)

这是使用 ASP.NET 5/MVC 6。请注意,我也尝试过使用 TraceWarning 和 TraceError ,但没有成功。我还尝试打开 Azure 中的所有日志记录选项,但这似乎也没有任何作用。

Sta*_*cev 1

跟踪搜索在带有 ASP.NET 5 的 Azure 上不起作用。这是已知错误

您可以使用 HttpPlatformHandler 登录到文件系统。

放入你的wwwroot目录下的web.config文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <customErrors mode="Off" />
  </system.web>
  <system.webServer>
    <handlers>
      <add
        name="httpPlatformHandler"
        path="*"
        verb="*"
        modules="httpPlatformHandler"
        resourceType="Unspecified"/>
    </handlers>
    <httpPlatform
      processPath="%DNX_PATH%"
      arguments="%DNX_ARGS%"
      stdoutLogEnabled="true"
      stdoutLogFile="..\..\LogFiles\httpplatform\httpplatform-stdout.log"
      startupTimeLimit="3600"/>
  </system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)

日志记录设置位于此处:

      stdoutLogEnabled="true"
      stdoutLogFile="..\..\LogFiles\httpplatform\httpplatform-stdout.log"
Run Code Online (Sandbox Code Playgroud)

确保 Azure 的文件系统中存在用于日志记录的目录。

您必须使用标准日志记录机制来写入日志