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

标签 c# azure azure-web-app-service asp.net-core-mvc system.diagnostics

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

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

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

Azure Screenshot

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

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

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

最佳答案

跟踪搜索在带有 ASP.NET 5 的 Azure 上不起作用。This is known bug

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

将 web.config 文件放入您的 wwwroot 目录中:

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

日志记录设置位于此处:

      stdoutLogEnabled="true"
      stdoutLogFile="..\..\LogFiles\httpplatform\httpplatform-stdout.log"

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

您必须使用standart logging mechanism用于写入日志

关于c# - Azure 应用程序日志记录不适用于我的 Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34343403/

相关文章:

用于文件处理的 Azure 后台服务

c# - 未知错误 : insufficient parameters supplied to the command

c# - 在编程更改工作簿时隐藏 Excel 2013

c# - 如何分离类和命名技术逻辑?

c# - 从 DLL/头文件中提取信息

azure - 设备未报告 IoT Edge 自定义模块

azure - 从 Azure 流分析到 Power Bi Desktop

azure - NLog with Application Insights - 将异常记录为异常而不是跟踪

mysql - Azure 多容器 Web 应用程序明显无缘无故地停止了该站点

azure - 您可以使用托管标识从 Azure 应用服务访问 Azure Function 吗?