在IIS中运行的ASP.NET核心启动错误日志记录

问题描述:

如何捕获IIS托管的ASP.NET Core应用程序中的启动错误?我正在尝试捕获在ConfigureServices中引发的异常,该异常仅在IIS托管环境中发生.

How do you capture startup errors in an ASP.NET Core app hosted in IIS? I'm trying to capture exceptions thrown in ConfigureServices which occurs only in the IIS hosted environment.

我遇到了此问题,因为丢失了ConfigureServices中加载的证书文件,并且未写入与通过日志配置配置的应用程序日志文件不同的日志文件中,未捕获到该文件(请注意,日志记录系统未初始化) ConfigureServices之前).在这种情况下,stderr将包含该异常,但是IIS是否会捕获该异常并将其记录在某个地方?

I came across this as a certificate file loaded in ConfigureServices was missing and it was not captured without writing to a different log file than the application log file configured through log configuration (note that the logging system doesn't get initialised before ConfigureServices). In this case stderr would contain the exception but does IIS capture it and log it somewhere?

用于IIS的ASP.NET Core模块具有stdoutLogEnabledstdoutLogFile可选参数:

<aspNetCore processPath="dotnet" 
            arguments=".\MyApp.dll" 
            stdoutLogEnabled="true" 
            stdoutLogFile=".\logs\stdout" />