我正在尝试将AWS CloudWatch Logs用作我的ASP.NET Core应用程序上的日志记录目标。我正在使用官方的AWS NuGet软件包AWS.Logger.AspNetCore
。
我使用以下策略创建了一个IAM角色,并将其附加到我的EC2实例:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogGroups"
],
"Resource": [
"arn:aws:logs:*:*:*"
]
}
]
}
在我的appsettings.json
中,添加了以下内容:
{
"AWS.Logging": {
"Region": "ap-southeast-2",
"LogGroup": "<my app>",
"LogLevel": {
"Default": "Warning",
"System": "Warning",
"Microsoft": "Warning"
}
}
}
在我的Startup.cs
文件中,我在Configure
方法下添加了以下内容:
loggerFactory.AddAWSProvider(this.Configuration.GetAWSLoggingConfigSection());
启动我的应用程序时,出现以下错误:
Application startup exception
System.NullReferenceException: Object reference not set to an instance of an object.
at <My.Application>.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) in <My.Application>/Startup.cs:line 81
End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
Startup.cs:81
包含:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
我能够使用AWS CLI成功执行EC2实例内的所有CloudWatch Logs操作。
库AWS.Logger.AspNetCore
是否需要更多权限?