简体   繁体   English

在哪里可以找到 Azure 应用服务的 docker 容器日志

[英]Where can I find docker container logs for Azure App Service

I do have a Docker container running a .net core 2 app.我确实有一个运行 .net core 2 应用程序的 Docker 容器。

The logging is configured using this code in Program.cs使用Program.cs此代码配置日志记录

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .ConfigureLogging((hostingContext, logging) =>
        {
            logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
            logging.AddConsole();
            logging.AddDebug();
        })
        .UseStartup<Startup>();

and the appsettings.json fileappsettings.json文件

{
  "Logging": {
    "LogLevel": {
      "Default": "Information"
    }
  },
}

Logging seems to be Ok, when running Kestrel directly, I can see the logs in the terminal.日志好像还可以,直接运行Kestrel的时候,可以在终端看到日志。 Same thing, when containerized: the command docker logs shows what I want.同样的事情,当容器化时:命令docker logs显示了我想要的。

Troubles arise in production, when run in as a container in Azure Web App.当在 Azure Web App 中作为容器运行时,生产中会出现问题。 I cannot find any consistent docker logs.我找不到任何一致的 docker 日志。

I made attempts to visit the Log file via FTP or via the url https://[mysite].scm.azurewebsites.net/api/logs/docker the log files are almost empty for example, https://[mysite].scm.azurewebsites.net/api/vfs/LogFiles/2018_09_09_RD0003FF74F63E_docker.log , only container starting lines are present我尝试通过 FTP 或通过 url https://[mysite].scm.azurewebsites.net/api/logs/docker访问日志文件,日志文件几乎是空的,例如https://[mysite].scm.azurewebsites.net/api/vfs/LogFiles/2018_09_09_RD0003FF74F63E_docker.log ,仅存在容器起始行在此处输入图片说明

Also I do have the same lines in the usual portal interface.此外,我在通常的门户界面中也有相同的行。

The question is: do docker logs are automatically output in docker.log files in Azure Web App?问题是:Azure Web App 的 docker.log 文件中会自动输出 docker 日志吗? Is there something that I am missing?有什么我想念的吗?

Firstly you need to enable container logs首先你需要启用容器日志

[App Service] -> Monitoring -> App Service logs [应用服务] -> 监控 -> 应用服务日志

应用服务登录监控应用服务

Then you can see container logs in [App Service] -> Monitoring -> Log stream然后就可以在【应用服务】->监控->日志流中看到容器日志

在日志流中查看容器日志

UPD UPD

Also you can find logs in KUDU您也可以在 KUDU 中找到日志在此处输入图片说明

Then "Current Docker Logs"然后是“当前 Docker 日志”

在此处输入图片说明

I've been cursing this for a good while, and eventually found something that works for me.我一直在诅咒这个很长一段时间,最终找到了对我有用的东西。

First I enabled filesystem logging as per @dima_horror's answer.首先,我根据@dima_horror 的回答启用了文件系统日志记录。

Next I ran a command-line az webapp log tail --name myApp --resource-group myRg接下来我运行了一个命令行az webapp log tail --name myApp --resource-group myRg

That now seems to give me useful output (it gave me nothing prior to enabling filesystem logging).现在似乎给了我有用的输出(在启用文件系统日志记录之前它没有给我任何东西)。

Have you checked the logs in container settings?您是否检查了容器设置中的日志? I followed this guide to deploy a container to Azure web app.我按照指南将容器部署到 Azure Web 应用程序。

容器日志

To add to the answers, if you're having trouble with deploying the image in your App Service and need logs for that specifically, you can get the docker logs for the provisioning phase of your container under Deployment Center, eg:为了补充答案,如果您在应用服务中部署映像时遇到问题并且需要专门的日志,您可以在部署中心下获取容器预配阶段的 docker 日志,例如:

在此处输入图片说明

I have the same exact issue, the App Service container logs is generic and vague.我有同样的问题,应用服务容器日志是通用的和模糊的。 This is not the same logs that Docker shows us whenever we run a container.这与每当我们运行容器时 Docker 向我们显示的日志不同。

17/02/2020 08:59:25.186 INFO - Site: tutorial-api - Start container succeeded. Container: f8bfa7e27680c0e9551c6157f9d1c8a73c9a3e739b4f15de8586ce52809798d3 17/02/2020 08:59:30.675 INFO - Site: tutorial-api - Application Logging (Filesystem): On 17/02/2020 08:59:44.106 INFO - Site: tutorial-api - Waiting for container to be ready 17/02/2020 08:59:49.116 INFO - Site: tutorial-api - Container has exited 17/02/2020 08:59:49.117 ERROR - Site: tutorial-api - Container could not be started 17/02/2020 08:59:49.120 INFO - Site: tutorial-api - Purging after container failed to start 17/02/2020 08:59:49.120 ERROR - Site: tutorial-api - Unable to start container. Error message: Container could not be started: tutorial-api_20

"Unable to start container, container couldn't be started" “无法启动容器,无法启动容器”

Wow!哇! Azure just told me every 60 seconds a minute has passed. Azure 只是告诉我每 60 秒一分钟过去一次。

I understand that this is production environment, but you got to give us something!我知道这是生产环境,但你必须给我们一些东西!

Out of frustration, I decided to run same image in a Azure Container Instance resource, there it shows you the same detailed logs that Docker provides (see screenshot below)出于沮丧,我决定在 Azure 容器实例资源中运行相同的图像,它会向您显示 Docker 提供的相同详细日志(请参见下面的屏幕截图)

在此处输入图片说明

Now that's what I'm talking about!现在这就是我要说的!

Using the error logs in Azure Container Instance, I found out that my App Service couldn't access the Sql Server resource (even though they are within the same resource group).使用 Azure 容器实例中的错误日志,我发现我的应用服务无法访问 Sql Server 资源(即使它们在同一个资源组中)。 I simply enabled the Sql Server resource to be accessed within the same resource group我只是启用了在同一资源组中访问的 Sql Server 资源

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在哪里可以找到我在 azure 应用服务中的日志? - Where do I find my logs in azure app services? 在哪里可以找到Window服务事件日志? - Where can I find Window service event logs? Azure 容器应用服务。 Docker 运行参数? - Azure container app service. Docker Run parameters? 如何使用只读用户访问 azure 应用服务的 log4net 日志文件夹 - How can I access a log4net logs folder for an azure app service with a readonly user Azure 应用服务多容器 - 对内部容器的 http 请求(docker compose) - Azure app service multi container - http request to internal container (docker compose) Ocelot 部署到 azure 应用服务时找不到 api - Ocelot can't find api when deployed to azure app service 在哪里可以找到Matroska容器的“真实”规格? - Where can I find the Matroska Container “Real” Specification? 为什么即使在Azure中配置了必需的设置后也看不到应用程序服务中的日志? - Why I do not see logs in app service even after configuring required settings in Azure? 为Azure App Service创建Blob容器 - Create blob container for Azure App Service Elmah.Mvc错误日志存储在哪里? 如何将它们存储在Azure SQL数据库中? - Elmah.Mvc where are the error logs stored? How can I store them in an azure SQL database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM