如何调试或查看在Elastic Beanstalk中部署的.NET Core应用程序的输出? [英] How to debug or see output for a .NET Core app deployed in Elastic Beanstalk?
问题描述
特别是我对能够通过其界面查看输出感兴趣.例如,是否有ILogger.LogFoo
方法或Console.WriteLine
出现在 Monitoring 或 Logs 选项卡中或其他位置?
Specifically I am interested in being able to see output via their interface. For instance, is there anyway to get the ILogger.LogFoo
methods or Console.WriteLine
to show up in either the Monitoring or Logs tabs or anywhere else?
在应用需要部署到其他地方的情况下,我试图远离AWS专有的查看输出方式.
I am trying to stay away from proprietary AWS ways of seeing output in case the app needs to be deployed elsewhere.
推荐答案
无法在Elastic Beanstalk界面中显示基于Windows的应用程序的日志.几个月前,我特别要求AWS对此提供支持,并收到以下答复,告诉我改用CloudWatch:
There's no way to make a Windows-based application's logs show up in the Elastic Beanstalk interface. I specifically asked AWS support this a few months back and received the following reply telling me to use CloudWatch instead:
你好
beanstalk日志使用它自己的逻辑来收集日志.在里面 linux verison可以将文件简单地添加到路径中 的日志记录,但是在Windows中,日志是分别收集的 由于他们使用其他类型的日志记录驱动程序来收集日志, 因此,不可能简单地将文件添加到路径并查看 它们显示在beantalk日志中.
The beanstalk logs uses it's own logic to collect the logs. In the linux verison of it it is possible to simply add the file to the path of the logging, but in windows the logs are collected individually since they use a different type of logging driver to collect the logs, therefore it is not possible to simply add files to a path and see them show up in the beanstalk logging.
除了使用内置的beantalk日志记录外,您还能做什么? cloudformation [sic] 代替.
what you can do instead of using the built in beanstalk logging is use cloudformation [sic] logs instead.
http://docs.aws.amazon.com/AmazonCloudWatch/Latest/logs/WhatIsCloudWatchLogs.html
通过此操作,您应该可以设置一个记录器,该记录器将使您能够 将日志直接发送到Amazon cloudwatch日志.
with this you should be able to set up a logger that will allow you to send logs directly to amazon cloudwatch logs.
最诚挚的问候,
以利亚f.亚马逊网络服务
elijah f. Amazon Web Services
出于谨慎的考虑,您要避免将所有日志记录代码紧密结合在一起-正如您在问题中提到的那样-专有的AWS查看输出方式" .但是,通过使用ASP.NET Core框架的 AWS.Logger.AspNetCore
日志记录提供程序,它将ASP.NET Core的内置记录器与CloudWatch集成在一起.
It is probably prudent that you want to avoid making all of your logging code be tightly coupled to - as you put it in the question - "proprietary AWS ways of seeing output". However, it's possible to use CloudWatch with only loose coupling by using the ASP.NET Core framework's standard logging together with the AWS.Logger.AspNetCore
logging provider that integrates ASP.NET Core's built-in logger with CloudWatch.
基于对将此功能添加到当前公司的代码库中的提交的一瞥,我认为为了使其能够正常工作,我必须进行以下更改,主要是基于官方的ASP.NET Core Cloudwatch集成 https://github.com/aws/aws上的示例-logging-dotnet/tree/master/samples/AspNetCore/WebSample :
Based upon a glance over the commit in which I added this feature to my current company's codebase, I think that in order to get it working I had to make the following changes, mostly based upon the official ASP.NET Core Cloudwatch integration example at https://github.com/aws/aws-logging-dotnet/tree/master/samples/AspNetCore/WebSample:
-
运行
Run
Install-Package AWS.Logger.Core
Install-Package AWS.Logger.AspNetCore
添加
Add
loggerFactory.AddAWSProvider(Configuration.GetAWSLoggingConfigSection());
到我应用程序的
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
方法(模板应用程序包含对 method in 在我的 Add an loggerFactory.AddConsole(Configuration.GetSection("Logging"));
和loggerFactory.AddDebug();
的调用的相同位置.Startup.cs
(the same place that the template application contains calls to loggerFactory.AddConsole(Configuration.GetSection("Logging"));
and loggerFactory.AddDebug();
.appsettings.config
文件的根目录中添加一个AWS.Logging
部分:AWS.Logging
section to the root of my appsettings.config
file:{
"AWS.Logging": {
"Region": "us-west-2",
"LogGroup": "put-whatever-name-you-like-here",
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
...
}
按照 http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/AWSHowTo.cloudwatchlogs.html#AWSHowTo.cloudwatchlogs.permissions ,在
Per the instructions at http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/AWSHowTo.cloudwatchlogs.html#AWSHowTo.cloudwatchlogs.permissions, create a custom policy at https://console.aws.amazon.com/iam/home#/policies with the following content:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:GetLogEvents",
"logs:PutLogEvents",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams",
"logs:PutRetentionPolicy"
],
"Resource": [
"arn:aws:logs:us-west-2:*:*"
]
}
]
}
,然后将其附加到aws-elasticbeanstalk-ec2-role
上的
and then attach it to the the aws-elasticbeanstalk-ec2-role
at https://console.aws.amazon.com/iam/home#/roles/aws-elasticbeanstalk-ec2-role. (Note that us-west-2
in the JSON above is specific to my application, since that's the region that it's deployed in, and that aws-elasticbeanstalk-ec2-role
is the default role for Elastic Beanstalk instances - you may need to attach the policy to a different role if you're bringing up instances with a different role.)
完成所有操作后,您的ILogger
应该登录到CloudWatch.如果您访问 https://console.aws.amazon.com/cloudwatch/home ,单击边栏中的日志" ,然后单击名称与appsettings
文件中的LogGroup
设置匹配的日志组,您应该可以看到您的日志.
Once all that is done, your ILogger
s should log to CloudWatch. If you go to https://console.aws.amazon.com/cloudwatch/home, click "Logs" in the sidebar, and then click on the log group whose name matches the LogGroup
setting in your appsettings
file, you should be able to see your logs.
这篇关于如何调试或查看在Elastic Beanstalk中部署的.NET Core应用程序的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!