40

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.

Andrew Williamson
  • 8,299
  • 3
  • 34
  • 62
  • 3
    I wasted much time not noticing that I had `stdoutLogEnabled="false"`, which I have not modified myself so go figure... – isapir Jul 06 '20 at 04:32

7 Answers7

44

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)
davidsbro
  • 2,761
  • 4
  • 23
  • 33
Vlatko Vlahek
  • 1,839
  • 15
  • 20
20

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.

Andrew Williamson
  • 8,299
  • 3
  • 34
  • 62
  • 1
    For me it was adding the logg folder at the root, next to approot and wwwroot, with stdoutLogFile="..\logs\stdout.log" – piris Jul 28 '17 at 10:01
  • What kind of permission should folder have? – mko Mar 31 '20 at 16:24
  • read and execute, list, write (potentially write is missing by default) - see [Vlatko's answer](https://stackoverflow.com/a/40547942/2363967) – Andrew Williamson Apr 01 '20 at 21:50
  • Seems like this have been fixed in newer versions. Currently running IIS 10 and this folder was created together with the log file. – 01F0 Aug 19 '21 at 07:39
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.

Francisco Goldenstein
  • 13,299
  • 7
  • 58
  • 74
  • 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) – samneric Aug 20 '19 at 21:39
3

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>

kasptom
  • 2,363
  • 2
  • 16
  • 20
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"

Community
  • 1
  • 1
G. Siganos
  • 747
  • 1
  • 12
  • 21
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.

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.

Himalaya Garg
  • 1,525
  • 18
  • 23