问题描述
当我尝试在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 (将#修改为@)