SteGriff

Blog

Next & Previous

How to see the console errors of an ASP.Net Core/6+ site

During early deployments of an ASP.Net Core/6/7/8 etc. site, you might not have logging set up. Or, you might have a logging provider which your app is unable to reach.

In all kinds of situations like this, I’d say to myself “if only I could see the console window while IIS runs it!”

Fortunately, you kind of can (see the output, at least).

ASP.Net Core sites don’t necessarily deploy with a web.config file, but you can add one, and the minimal version looks something like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <modules>
        <remove name="WebDAVModule" />
      </modules>
      <handlers>
        <remove name="WebDAV" />
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\ACME.WebApi.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>
<!--ProjectGuid: ... -->

(Come to think of it, I probably added that stuff to remove the WebDAV module so that we could handle PUT verb…)

Check out this really obvious switch:

stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout"

😮😮😮

It turns out you can just turn on logging stdout to file. Flip it to true and the site will automatically restart. Hit some requests to your site, and after a moment, you should see a logs directory gets created in your app folder. Open that up and there’s a timestamped file which you can read to see exactly what your app is thinking!

This really helped me out when connections to the SQL server suddenly stopped working due to an SSL error! 😂

Oh, first post of the year 🎆 Happy 2024!