我正在使用Amazon.Lambda.Logging.AspNetCore
在CloudWatch上写日志,它是github link。这是asp.netcore 2.1 c#lambda。我有两个应用设置文件-appsettings.json
和appsettings.staging.json
。除了“ Lambda.Logging”的值外,其他所有设置都已从appsettings.staging.json
文件中覆盖
appsettings.json
设置被添加到下面
"Lambda.Logging": {
"IncludeCategory": true,
"IncludeLogLevel": true,
"IncludeNewline": true,
"LogLevel": {
"Default": "Debug",
"System": "Debug",
"Microsoft": "Information"
}
},
"Logging": {
"LogLevel": {
"Default": "Information",
"System": "Information",
"Microsoft": "Information"
}
},
以及appsettings.staging.json
"Lambda.Logging": {
"IncludeCategory": false,
"LogLevel": {
"Default": "Information",
"System": "Information",
"Microsoft": "Information"
}
},
在lambda上添加的包裹是
<PackageReference Include="Amazon.Lambda.Core" Version="1.0.0" />
<PackageReference Include="Amazon.Lambda.Logging.AspNetCore" Version="2.0.0" />
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="1.3.0" />
<PackageReference Include="Amazon.Lambda.SQSEvents" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" />
以及用于构建配置的代码
var environmentName = Environment.GetEnvironmentVariable(Env.DotNetCoreEnvironment) ?? string.Empty;
var location = Assembly.GetExecutingAssembly().Location;
var builder = new ConfigurationBuilder()
.SetBasePath(Path.GetDirectoryName(location))
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{environmentName.ToLower()}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables();
return builder.Build();
有什么我想念的吗?还是这个软件包只需从一个文件中读取设置
请注意:我已经检查了文件“ appsettings.staging.json”的出口。并且其他配置也已被覆盖。