【Azure 应用服务】当在Azure App Service的门户上 Log Stream 日志无输出,需要如何操作让其输出Application Logs呢?

问题描述

在Azure App Service的门户上 Log Stream 日志无输出,需要如何操作让其输出Application Logs呢?

如下图所示:

问题解答

请注意,上图中提示说:Application logs are switched off.  You can turn them on using the App Service Logs Settings. 应用日志关闭,可以通过App Service Logs 页面来设置开启。

App Service ---> App Service Logs :  针对Application Logging 和 Web Server Logging 为On,最后点击页面上的Save按钮。

保存后,返回Log Stream页面,就可以实时查看App Service中的输出日志:

附录1:.NET API下的日志输出示例

using Microsoft.AspNetCore.Mvc;

namespace myapi01.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class AASController : ControllerBase
    {
        private readonly ILogger<AASController> _logger;
        public AASController(ILogger<AASController> logger)
        {
            _logger = logger;
        }

        [HttpGet]
        [Route("/log")]
        public string GetLog()
        {
            _logger.LogInformation("this is test massge informaiton level!!!!!!!");

            _logger.LogWarning("this is test massge Warning level!!!!!!!");

            _logger.LogError("this is test massge Error level!!!!!!!");

            _logger.LogDebug("this is test massge debug level!!!!!!!");

            _logger.LogCritical("this is test massge Critical level!!!!!!!");

            _logger.LogTrace("this is test massge Trace level!!!!!!!");

            return "Outpu logs - today 2023-04-18 03:56";
        }

        [HttpGet]
        [Route("/exp")]
        public string Getexception()
        {
            throw new Exception("thsi is my custome exception today.");
        }

    }
}

 

posted @ 2023-04-18 21:15  路边两盏灯  阅读(90)  评论(0编辑  收藏  举报