Буду признателен за рекомендации по настройке приемника Serilog для AWS CloudWatch с .NET Core.Я использую appsettings.json для настройки, но я не могу поместить настройки в логгер.При попытке записать информацию журнала в CloudWatch появляется эта ошибка:
An error occurred while starting the application.
AmazonClientException: No RegionEndpoint or ServiceURL configured
Amazon.Runtime.ClientConfig.Validate() in ClientConfig.cs, line 446
AmazonClientException: No RegionEndpoint or ServiceURL configured
Amazon.Runtime.ClientConfig.Validate() in ClientConfig.cs
Amazon.Runtime.AmazonServiceClient..ctor(AWSCredentials credentials, ClientConfig config) in AmazonServiceClient.cs
AWS.Logger.Core.AWSLoggerCore..ctor(AWSLoggerConfig config, string logType) in AWSLoggerCore.cs
AWS.Logger.SeriLog.AWSSink..ctor(AWSLoggerConfig loggerConfiguration, IFormatProvider iFormatProvider, ITextFormatter textFormatter) in AWSSink.cs
AWS.Logger.SeriLog.AWSLoggerSeriLogExtension.AWSSeriLog(LoggerSinkConfiguration loggerConfiguration, IConfiguration configuration, IFormatProvider iFormatProvider, ITextFormatter textFormatter) in AWSLoggerSeriLogExtension.cs
...
Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
Microsoft.Extensions.DependencyInjection.IServiceCollectionExtensions+InjectApiVersionRoutePolicy+<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
Microsoft.AspNetCore.Server.IISIntegration.IISSetupFilter+<>c__DisplayClass4_0.<Configure>b__0(IApplicationBuilder app)
Microsoft.AspNetCore.HostFilteringStartupFilter+<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter+<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder builder)
Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
Мой код выглядит следующим образом:
В файле Startup.cs:
public Startup(IHostingEnvironment env)
{
Configuration = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables()
.Build();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(Configuration.GetSection("AWS.Logging"))
.WriteTo.AWSSeriLog(Configuration)
.CreateLogger();
app.UseMvc();
}
Мои настройки приложения.json:
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AWS.Logging": {
"Region": "eu-west-1",
"LogGroup": "MyLogGroup",
"LogLevel": {
"Default": "Information",
"System": "Information",
"Microsoft": "Information"
}
},
"AllowedHosts": "*"
}
Учетные данные для AWS с моего компьютера разработчика устанавливаются с помощью переменных среды:
AWS_ACCESS_KEY_ID=xxxxxxxxxx
AWS_DEFAULT_REGION=eu-west-1
AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxx