查看 Azure 中 AppService 的日志

问题描述 投票:0回答:1

您好,我有一个简单的应用程序,我想在其中实现日志,这样当错误发生时,我可以在 Azure 中的文件中查看错误。

我读了他们描述的一些文章来查看错误监控。我实际上想看到添加到某个文件中的错误。因此,当部署的应用程序中发生错误时,我应该能够转到日志文件并读取错误或信息。

非常简单,我创建了一个新的 ASP.NET 6 API,它随 Ilogger 一起提供。现在考虑一下,如果我将此应用程序部署到 Azure,如果出现错误,我如何在文件中看到它?

azure-web-app-service azure-log-analytics azure-diagnostics
1个回答
0
投票

当我们将

.NET Core App
部署到
Azure App service
时(使用
Visual Studio Publish option
/
GitHub Actions
/
VS Publish Import Profile
),部署过程中默认会生成
Web.config
文件。

  • 您可以在应用程序根目录下查看
    site/wwwroot

enter image description here

  • 检查文件中日志的最简单方法是将

    stdoutLogEnabled
    值更改为
    true

  • 单击编辑按钮打开

    web.config
    文件。

  • 更新

    stdoutLogEnabled
    值后。运行应用程序。如果出现任何错误/无法访问部署的 URL,将在
    Logfiles
    文件夹中生成包含明确错误信息的文件。

路径: -

C:\home\LogFiles

enter image description here

  • 运行应用程序时,每次部署后都会生成新文件。

enter image description here

检查

SOThread
中的Note section以在本地使用
web.config

使用

AddAzureWebAppDiagnostics

MSDoc中所述,

通过使用 AddAzureWebAppDiagnostics,我们可以将日志写入 Azure 应用服务应用程序文件系统中的文本文件

请参阅我发布的SOthread中的第一部分。

App Service logs
中,启用
Application logging
并将日志记录级别更改为
Error

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.