[英]ASP.NET Core program.cs configuration
I am converting code to a .net core application.我正在将代码转换为 .net 核心应用程序。 In my original application, I have the following code in my startup.cs
:在我的原始应用程序中,我的startup.cs
中有以下代码:
public void Configure(IApplicationBuilder app,
WebHostEnvironment env,
ApplicationDbContext dataContext,
ILoggerFactory loggerFactory,
IHttpContextAccessor httpContextAccessor,
IHostApplicationLifetime applicationLifetime)
{
ConfigureSeriLog(httpContextAccessor);
loggerFactory.AddSerilog();
app.UseSerilogRequestLogging();
}
I need to bring this configuration into the program.cs
of my new application.我需要将此配置带入我的新应用程序的program.cs
中。 Since program.cs
does not have a Configure
method, how do I gain access to httpContextAccessor
so I can pass it to ConfigureSerilog
?由于program.cs
没有Configure
方法,我如何访问httpContextAccessor
以便将其传递给ConfigureSerilog
?
In your program you can do this to get access to that.在您的程序中,您可以执行此操作以访问它。
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
You can do everything you need with the two items above like you use to in older version.您可以像在旧版本中一样使用上述两项来完成所需的一切。
Here is link to do most other examples as well: https://docs.microsoft.com/en-us/aspnet/core/migration/50-to-60-samples?view=aspnetcore-6.0以下是大多数其他示例的链接: https://docs.microsoft.com/en-us/aspnet/core/migration/50-to-60-samples?view=aspnetcore-6.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.