如何在已发布的 asp.net 核心项目中启用日志记录?

How to enable logging in published asp.net Core projects?

我在 iis 服务器中发布了我的 asp.net 核心网络 api,当我在浏览器中测试该应用程序时,出现 502.5 错误。

我搜索了如何找到解决方案,我发现我需要通过将 stdoutLogEnabled="false" 更改为 true 来启用日志记录。

 <?xml version="1.0" encoding="utf-8"?>
    <configuration>
       <location path="." inheritInChildApplications="true">
       <system.webServer>
         <handlers>
         <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
  </handlers>
      <aspNetCore processPath="dotnet" arguments=".\WsAZProjet.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
      </system.webServer>
      </location>
    </configuration>
<!--ProjectGuid: baf7ef69-c0ff-4e36-b69c-71ad3fd869b9-->

我在 iis 服务器中更改了它并在浏览器中重新测试了应用程序,但我没有生成日志目录,所以我认为我应该在代码中配置它然后重新发布应用程序?

您知道如何为已发布的应用程序启用日志记录吗? 我应该重新启动 iis 才能正常工作吗?

更新

搜索后,我发现 here 我需要手动创建 logs 文件夹,我这样做并进行了测试再次应用程序,我在文件夹下得到一个 log_stdout 文件,但它是空的!!?

已解决,here错误原因:

不正确的 proecessPath,缺少 PATH 变量,或 dotnet.exe 访问冲突

Browser: HTTP Error 502.5 - Process Failure

Application Log: Failed to start process with commandline ‘“dotnet” .\my_application.dll’ (portable app) or ‘”.\my_application_Foo.exe”’ (self-contained app), ErrorCode = ‘0x80070002’.

ASP.NET Core Module Log: Log file created but empty

Troubleshooting: Check the processPath attribute on the element in web.config to confirm that it is dotnet for a portable application or .\my_application.exe for a self-contained application. For a portable application, dotnet.exe might not be accessible via the PATH settings. Confirm that C:\Program Files\dotnet\ exists in the System PATH settings. For a portable application, dotnet.exe might not be accessible for the user identity of the Application Pool. Confirm that the AppPool user identity has access to the C:\Program Files\dotnet directory.

我的 processPath 昨天被我设置为 C://ProgramFiles/dotnet.exe ,将其更改为 dotnet 解决这个问题,我现在得到我的日志文件信息。