![](/img/trans.png)
[英]How do I post an IFormFile in 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?
我希望使用nuget包AWS.Logger.AspNetCore在ASP.NET Core 2.0 Razor Pages應用程序中實現ASP.NET Core日志記錄 。
項目站點上的示例基於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 在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");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.