如何将 AWS ASP.NET Core Logging 添加到 ASP.NET Core 2.0 Razor Pages 应用程序?
How do you add AWS ASP.NET Core Logging to an ASP.NET Core 2.0 Razor Pages app?
我希望在 ASP.NET Core 2.0 Razor Pages 应用程序中使用 nuget 包 AWS.Logger.AspNetCore to implement 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 Pages,而不是 MVC)
我查看了 Microsoft 的 page on Logging in ASP.NET Core,它展示了如何添加提供程序,但我不知道如何将其与在 Startup.cs
中添加 AWS Logger 联系起来
剃须刀的方法大致相同
public class PersonModel : PageModel {
ILogger<PersonModel> Logger { get; set; }
public PersonModel(ILogger<PersonModel> logger)
{
this.Logger = logger;
}
}
无论如何,只要确保你声明了一个私有类型那么简单
然后在构造函数中注入。初创公司 LoggerFactory 正在为您将 AWS 注入记录器。然后您将记录器用作普通。
// code to log out to AWS and load the Person.cshtml page
public void GetAsync(){
Logger.LogInformation("Welcome to the AWS Logger. You are viewing the home page");
}
我希望在 ASP.NET Core 2.0 Razor Pages 应用程序中使用 nuget 包 AWS.Logger.AspNetCore to implement 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 Pages,而不是 MVC)
我查看了 Microsoft 的 page on Logging in ASP.NET Core,它展示了如何添加提供程序,但我不知道如何将其与在 Startup.cs
中添加 AWS Logger 联系起来剃须刀的方法大致相同
public class PersonModel : PageModel {
ILogger<PersonModel> Logger { get; set; }
public PersonModel(ILogger<PersonModel> logger)
{
this.Logger = logger;
}
}
无论如何,只要确保你声明了一个私有类型那么简单 然后在构造函数中注入。初创公司 LoggerFactory 正在为您将 AWS 注入记录器。然后您将记录器用作普通。
// code to log out to AWS and load the Person.cshtml page
public void GetAsync(){
Logger.LogInformation("Welcome to the AWS Logger. You are viewing the home page");
}