我在让 Azure 应用程序日志记录与我的 Web 应用程序配合使用时遇到问题。我可以成功发布并使用我的网络应用程序。然而,当我查看日志时,“应用程序”文件夹是空的。我可以成功地在 stdout.log 文件中看到我写入控制台的消息...但应用程序文件夹中从来没有任何内容。
至于我所尝试的,我已按照 here 概述的步骤进行操作。 。看起来很简单。配置 Azure 以打开应用程序日志记录,在代码中编写跟踪命令,并且内容应写入日志中的应用程序文件夹。我还尝试将应用程序日志记录 (Blob) 设置为打开,但我也没有看到其中写入任何内容。
下面是我在 Azure 中配置的屏幕截图:
这是我在代码中写入 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/