问题描述
在 Azure App Service 中运行 Web App 时,通过 Kudu(https://xxxxxxxxxx.scm.chinacloudsites.cn/ )访问文件系统,发现:
- /home/LogFiles 或 D:\home\LogFiles 下没有预期日志
- 特别是 application 目录(Application Log)未生成任何日志文件
- 应用已正常运行,但 Kudu 中无法查看应用日志
问题解答
在 Azure App Service 中,应用日志(Application Logging)默认是关闭的。
如果没有在App Service中显式开启“Application Logging (Filesystem)”功能,即使应用内部使用了日志框架(例如 ILogger、Log4j、console.log 等)输出日志,这些日志也不会自动落盘到 /home/LogFiles/Application 或 D:\home\LogFiles\Application 路径中。
因此,在 Kudu 中查看不到日志并不代表应用没有生成日志,而是这些日志没有被写入文件中。
当开启日志后,就可以在Kudu的Logfiles中查看到Application的日志文件,但是Filesystem 类型的日志本身具有临时性,它通常用于调试场景,会自动在12小时后关闭。
Enable application logging to collect diagnostic traces from your web app code. You'll need to turn this on to enable the streaming log feature. This setting turns itself off after 12 hours.
参考资料
App Service 日志配置文档:https://learn.microsoft.com/en-us/azure/app-service/troubleshoot-diagnostic-logs
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!