如何解决Asp.Net Core WebAPI使用AWS CloudWatch Log且未配置RegionEndpoint或ServiceURL错误
当我尝试在Azure App Service中部署Asp.Net Core WebApi时,出现以下错误。我的WebApi使用Serilog.Sinks.AwsCloudWatch
。
Exception Info: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> Amazon.Runtime.AmazonClientException: No RegionEndpoint or ServiceURL configured
at Amazon.Runtime.ClientConfig.Validate()
at Amazon.Runtime.AmazonServiceClient..ctor(AWSCredentials credentials,ClientConfig config)
at Amazon.CloudWatchLogs.AmazonCloudWatchLogsClient..ctor()
at Serilog.Sinks.AwsCloudWatch.AwsCloudWatchConfigurationExtension.AmazonCloudWatch(LoggerSinkConfiguration loggerConfiguration,String logGroup,ILogStreamNameProvider logStreamNameProvider,LogEventLevel restrictedToMinimumLevel,Int32 batchSizeLimit,Int32 batchUploadPeriodInSeconds,Boolean createLogGroup,Int32 queueSizeLimit,Byte maxRetryAttempts,LogGroupRetentionPolicy logGroupRetentionPolicy,ITextFormatter textFormatter,IAmazonCloudWatchLogs cloudWatchClient)
at Serilog.Sinks.AwsCloudWatch.AwsCloudWatchConfigurationExtension.AmazonCloudWatch(LoggerSinkConfiguration loggerConfiguration,String logStreamPrefix,Boolean appendUniqueInstanceGuid,Boolean appendHostName,IAmazonCloudWatchLogs cloudWatchClient)
--- End of inner exception stack trace ---
appSettings.json中的配置为
"Serilog": {
"Using": [ "Serilog.Sinks.AwsCloudWatch" ],"Region": "ap-southeast-2","WriteTo": [
{
"Name": "AmazonCloudWatch","Args": {
"logGroup": "test-logger","logStreamPrefix": "development","restrictedToMinimumLevel": "Error"
}
}
]
}
AWS凭证检索为
public class RegisterAwsCredentials
{
public static void Register()
{
var options = new CredentialProfileOptions
{
AccessKey = Environment.GetEnvironmentVariable("AWS.Key"),SecretKey = Environment.GetEnvironmentVariable("AWS.Secret"),};
var profile = new CredentialProfile("basic_profile",options);
profile.Region = RegionEndpoint.APSoutheast2;
var netSDKFile = new SharedCredentialsFile();
netSDKFile.RegisterProfile(profile);
}
}
当我在本地运行代码时,它可以正常工作。仅当我尝试将其部署到Azure中的App Service时才会发生。
任何人都可以给点建议吗?谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。