Where can I log an ASP.NET Core app's start/stop/error events?

后端 未结 4 1573
孤独总比滥情好
孤独总比滥情好 2020-12-14 16:24

In old ASP.NET, in the Global.asax.cs class, I would log when the app starts, stops and throws unhandled exceptions:

  • Application_Start()
4条回答
  •  悲&欢浪女
    2020-12-14 17:02

    Please see CaptureStartupErrors and the method .CaptureStartupErrors(true) that will help you find issues.

    This is especially handy when something runs perfect on localhost but fails in Azure.

    Here is my usual config for NetCore Web Apps:

    public static IWebHost BuildWebHost(string[] args) => WebHost
                .CreateDefaultBuilder(args)
                .CaptureStartupErrors(true)
                .UseKestrel()
                .UseIISIntegration()
                .UseStartup()
                .UseAzureAppServices()
                .Build();
    

    In Azure App Service you can then find the logs in the log stream in Kudu Tools https://.scm.azurewebsites.net/api/logstream

提交回复
热议问题