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

7

44

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:

<aspNetCore processPath="dotnet" arguments=".\XXX.Server.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />

So apparently, this should be logging to logs\stdout, but when I look, there's nothing there. I went on a wild goose chase, searching the whole disk for anything named 'log' (that returned too much) or 'stdout' (that returned nothing), and still couldn't figure it out.

Gottschalk answered 10/11, 2016 at 20:2 Comment(1)
I wasted much time not noticing that I had stdoutLogEnabled="false", which I have not modified myself so go figure...Brookins
B
46

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)
Bygone answered 11/11, 2016 at 12:22 Comment(7)
Why might IIS have permission to create the individual log files, but not the log folder?Gottschalk
@AndrewWilliamson I'm not sure about that unfortunately :(Bygone
@VlatkoVlahek My IIS_IUSRS has full permission for logs folder but no log file created!Kalbli
@Kalbli Can you check that in web.config your stdoutLogEnabled is set to true? Also, are there any errors inside the Event Viewer on app startup?Bygone
@VlatkoVlahek stdoutLogEnabled was true and there were some errors inside the Event Viewer also.Kalbli
@Kalbli Did you manage to resolve the issue in the meantime. I was out for a few days, sry.Bygone
i had the same issue as VlkoIzaak
G
23

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

Update - Nov 2022

The Microsoft documentation on Setting up logging for Asp.Net Core on IIS now specifically lists creating the 'Logs' folder as one of the steps. This implies that IIS will not create the folder if it doesn't exist.

This issue was raised in the Asp Net Core Module's repo on GitHub: Issue #30 - Logs are not created if the log folder does not exist. Their suggested workaround is to include a dummy '.log' file in the log directory, so that the log folder is created when you publish the site.

Gottschalk answered 10/11, 2016 at 20:2 Comment(4)
For me it was adding the logg folder at the root, next to approot and wwwroot, with stdoutLogFile="..\logs\stdout.log"Instep
What kind of permission should folder have?Deedeeann
read and execute, list, write (potentially write is missing by default) - see Vlatko's answerGottschalk
Seems like this have been fixed in newer versions. Currently running IIS 10 and this folder was created together with the log file.Tale
I
11

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.

Isochronous answered 28/8, 2018 at 18:33 Comment(1)
I like this because it uses an existing logging folder. For the life of me, I couldn't get any KuDu write actions to work on Azure (creating a new folder and editing web.config both gave me permission errors even though the files were not marked readonly)Smacker
F
4

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>

Foraminifer answered 23/8, 2018 at 0:7 Comment(0)
F
1

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"

Fleischer answered 22/5, 2019 at 8:32 Comment(0)
L
0

Check the event viewer. If you're like me you will see an entry in the Application\Event log "Could not create stdoutLogFile c:....logs\stdout_....". You have to create the logs folder there yourself. Once I created the "logs" folder stdout_.... files began to dump into it. Of course also be sure stdoutLogEnabled="true". The location of the expected folder location will be shown in the event viewer log. This is important because it may not be where you think it should be located.

Leper answered 6/1, 2021 at 11:29 Comment(0)
S
0

I noticed that the logs are not created immediately when you hit the website. I allowed write access for IIS_IUSRS, created 'logs' folder, restarted app_pool and after few minutes logs were there.

Shipwright answered 15/9, 2021 at 8:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.