Where do logs go when running ASP.NET Core on IIS 7.5?

后端 未结 5 911
野趣味
野趣味 2020-12-09 15:35

I\'m posting this and answering it, because this left me stumped for a very long time. I have the following line in my web.config:



        
相关标签:
5条回答
  • 2020-12-09 16:17

    According to the provided stdoutLogFile=".\logs\stdout" in your web.config file, the logs directory should be created next to the web.config, inside the publish directory.

    To create the logs subdirectory you can use the approach described in the ASP.NET Core directory structure.

    Just paste this at the end of your published project's *.csproj file

    <Project>
    ...
      <Target Name="CreateLogsFolder" AfterTargets="Publish">
        <MakeDir Directories="$(PublishDir)logs" 
                  Condition="!Exists('$(PublishDir)logs')" />
      </Target>
    </Project>
    

    During the publish process after this change the logs directory should be created if it does not exist in the output directory.

    If you run for example: dotnet publish --output <path_to_your_publish_folder> you should find the logs directory inside the <path_to_your_publish_folder>

    0 讨论(0)
  • 2020-12-09 16:21

    I did the following steps in order to get logs:

    1. Create a folder logs and give write access to IIS_IUSRS as described above
    2. Set absolute path in web.config: stdoutLogFile="C:\xxx\xxx\logs"
    3. Recycle the the application pool
    4. Stop, Start the Website

    Edit

    Step 2 works with relative path too stdoutLogFile=".\logs\stdout"

    0 讨论(0)
  • 2020-12-09 16:28

    You could probably check the Event Viewer on your machine -> Application to see if there are any errors logged, which could explain why your log files aren't being generated.

    However, the most probable reason is that IIS doesn't have a permission to write to that log folder.

    1. Right click on the folder -> Security
    2. Ensure that IIS_IUSRS user has the following permissions: read and execute, list, write (potentially write is missing by default)

    ** Copy logs/stdout folder to website root folder, for some reason logs are appearing here. (suggestion)

    0 讨论(0)
  • 2020-12-09 16:31

    You must make sure the log folder exists! IIS won't make it for you. Such a simple solution to this infuriating problem.

    0 讨论(0)
  • 2020-12-09 16:32

    I created the logs folder but still, nothing was logged. I found out that you can use an existing folder under home/logfiles and make it work without creating a folder. This solution worked for me as is:

    1) Open the web.config file that is created in the root folder of the published application.

    2) Set stdoutlogEnabled to true and stdoutLogFile to \?\%home%\LogFiles\stdout like this:

    <aspNetCore processPath="dotnet" arguments=".\SellCarsHereV2.dll" stdoutLogEnabled="true" stdoutLogFile="\\?\%home%\LogFiles\stdout" />
    

    Then you can either go to that path and download the files or use the Azure Portal (if it's hosted in Azure). If you are using the Azure Portal:

    1) Go to the app service.

    2) Go to Advanced Tools which takes you to https://{your app service}.scm.azurewebsites.net/

    3) Click on Debug Console menu --> CMD

    4) Click on LogFiles

    5) You'll see a file called stdout_*.log and you can click on the pencil to view it. You can also download the file if you want.

    0 讨论(0)
提交回复
热议问题