如何查看 Azure 应用服务日志文件?

H2O*_*aCl 4 asp.net logging azure-appservice

Visual Studio 2019 中的默认 API 示例实例化一个ILogger<T>. 如果我通过_logger.Log(LogLevel.Information, "hello")如何查看日志文件来调用它?此问题假设使用 Azure 应用服务。

namespace WebApplication1.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<WeatherForecastController> _logger;

        public WeatherForecastController(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Bao*_*uoc 6

  1. 您可以使用以下命令在 Cloud Shell 中实时流式传输日志:

    az webapp log tail --name appname --resource-group myResourceGroup

  2. 或者您可以导航到您的应用程序并选择日志流。

在此输入图像描述