【发布时间】:2018-10-27 10:34:15
【问题描述】:
我希望使用 nuget 包 AWS.Logger.AspNetCore 在 ASP.NET Core 2.0 Razor Pages 应用程序中实现 ASP.NET Core Logging。
项目站点上的示例基于 ASP.NET Core 1.0。
所以例子显示:
在 appsettings.json 文件中:
"AWS.Logging": {
"Region": "us-east-1",
"LogGroup": "AspNetCore.WebSample",
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
在 Startup.cs 中
public Startup(IHostingEnvironment env)
{
// Read the appsetting.json file for the configuration details
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
// Create a logging provider based on the configuration information passed through the appsettings.json
loggerFactory.AddAWSProvider(this.Configuration.GetAWSLoggingConfigSection());
...
有人可以在 ASP.NET Core 2.0 中显示等效的内容吗? 然后如何将记录器注入到 (.cshtml.cs) 页面后面的 Razor 代码中? (我使用的是 ASP.NET Core Razor 页面,而不是 MVC)
我查看了 Microsoft 的 page on Logging in ASP.NET Core,其中显示了如何添加提供程序,但我不知道如何将其与在 Startup.cs 中添加 AWS Logger 联系起来
【问题讨论】:
标签: c# amazon-web-services asp.net-core razor-pages