How to handle “An error occurred while starting the application” in an Azure WebApp

Björn Reinhardt
MAKONIS
Published in
2 min readJul 29, 2018

So when you’re creating your Azure web app (hosted on windows OS) and deploying some ASP.NET Core app you might see the following like I did the last time:

As the error message implies something get’s really bad while IIS was trying to start up your application.

And here’s the problem: How should your application log any exception while it’s not up and running??

Well… it can’t! But there is another way so IIS itself will log something useful by tweaking the applications web.config (changes are highlighted in bold):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\YOUR_API_ASSEMBLY.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>

Some things to consider:

  • set stdoutLogEnabled to true only for troubleshooting
  • stdoutLogFile points to an folder (not file) which must exist while IIS will restart next time. Otherwise you won’t see any logs.

The next time you restart your web app you should see some logs in your referenced folder.

By the way — do you know how to quickly edit your web.config and have a look on your logs from the Azure Portal?

Login to your Azure Portal and go to your web app. Within your app service blade choose App Service Editor (preview) and select Go:

A new tab will open where you should see the content of your wwwroot: one place to edit your web.config and read your logs.

You’re welcome! ;)

--

--