public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
   
    app.Run(async (context) =>
    {
        await context.Response.WriteAsync($"ApplicationName:{env.ApplicationName}");
        await context.Response.WriteAsync($"ContentRootPath:{env.ContentRootPath}");
        await context.Response.WriteAsync($"WebRootPath:{env.WebRootPath}");
        await context.Response.WriteAsync($"是否开发环境:{env.IsDevelopment()}");
    });
}

ASP.NET Core IHostEnvironment和IApplicationLifetime介绍

IApplicationLifetime站点启动或关闭时的监控

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime applicationLifetime)
{
    applicationLifetime.ApplicationStarted.Register(() =>
    {
        Console.WriteLine("ApplicationStarted");
    });
    applicationLifetime.ApplicationStopped.Register(() =>
    {
        Console.WriteLine("ApplicationStopped");
    });
    applicationLifetime.ApplicationStopping.Register(() =>
    {
        Console.WriteLine("ApplicationStopping");
    });
}

 

相关文章:

  • 2021-12-21
  • 2019-06-03
  • 2022-01-21
  • 2022-01-24
  • 2021-10-13
猜你喜欢
  • 2021-08-20
  • 2021-06-06
  • 2022-12-23
  • 2022-12-23
  • 2022-03-07
  • 2021-06-17
相关资源
相似解决方案