c# - Asp.Net Core WebAPI 使用没有 RegionEndpoint 或 ServiceURL 配置错误的 AWS CloudWatch Log
问题描述
当我尝试在 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 logGroup, String logStreamPrefix, LogEventLevel restrictedToMinimumLevel, Int32 batchSizeLimit, Int32 batchUploadPeriodInSeconds, Boolean createLogGroup, Int32 queueSizeLimit, Byte maxRetryAttempts, LogGroupRetentionPolicy logGroupRetentionPolicy, Boolean appendUniqueInstanceGuid, Boolean appendHostName, ITextFormatter textFormatter, 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 中的应用服务时才会发生。
任何人都可以给一些建议吗?谢谢
解决方案
推荐阅读
- arrays - 从字符串的开头查找单词的特定数量
- javascript - 如何找到特定数字的所有可能排列?
- javascript - 在 Javascript 中替换/附加 HREF 文件类型扩展名
- holoviews - 如何在 holoviews 布局中对齐网格空间图?
- typescript - Typescript如何处理本机接口
- java - 如何使用流获取数组列表的特定值
- c - C中uint16_t的多维数组
- v8 - 以二进制实现任意精度算术(例如 JavaScript 中的 BigInt)是否有原因?
- php - 使用 PHP 为 mySQL 数据库重置密码
- javascript - 反应本机webview中的EventListener