0

I am publishing an ASP.NET Core web API to an Azure App Service. I've published from Visual Studio 2022 and from an Azure DevOps pipeline. I'm trying to understand why the Visual Studio publish process is resulting in a different web.config file than the Azure DevOps pipeline.

My project does contain a web.config file with some request limits in it.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="52428800" />
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>

When I publish from either Visual Studio or DevOps, the publishing process adds the handler information for the aspNetCore module and an <aspNetCore> element.

   <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
   </handlers>
   <aspNetCore processPath=".\DocRecService.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />

When I publish from Visual Studio the stdoutLogFile location on the <aspNetCore> element is "\\?\%home%\LogFiles\stdout".

When I build and publish from the DevOps pipeline the stdoutLogFile location is .\logs\stdout.

I believe it's the dotnet publish task in the pipeline that is transforming the web.config file adding the aspNetCore modile information. I am passing it the following arguments to produce a self-contained app --configuration Release --runtime win-x64 --output $(Build.ArtifactStagingDirectory).

The web.config documentation states:

When an app is deployed to Azure App Service, the stdoutLogFile path is set to \?%home%\LogFiles\stdout.

But I can't find any explanation what is/should be setting the value. What is setting the value? How can I mimic that behavior in my Azure DevOps pipeline or outside of Visual Studio? Is it something in the publishing profile which is not being used by the DevOps pipeline? My main goal is just to gain a better understanding of the process.

IamMike
  • 111
  • 1
  • 4

1 Answers1

2

But I can't find any explanation what is/should be setting the value. What is setting the value?

Using the stdout log is only recommended for troubleshooting app startup issues when hosting on IIS or when using development-time support for IIS with Visual Studio, not while debugging locally and running the app with IIS Express.

The ASP.NET Core Module redirects stdout and stderr console output to disk if the stdoutLogEnabled and stdoutLogFile attributes of the aspNetCore element are set. Any folders in the stdoutLogFile path are created by the module when the log file is created. The app pool must have write access to the location where the logs are written (use IIS AppPool\{APP POOL NAME} to provide write permission, where the placeholder {APP POOL NAME} is the app pool name).

Don't use the stdout log for general app logging purposes. For routine logging in an ASP.NET Core app, use a logging library that limits log file size and rotates logs. For more information, see third-party logging providers.

When publishing an app for Azure App Service deployment, the Web SDK sets the stdoutLogFile value to \\?\%home%\LogFiles\stdout. The %home environment variable is predefined for apps hosted by Azure App Service.

<aspNetCore processPath="dotnet"
    arguments=".\MyApp.dll"
    stdoutLogEnabled="true"
    stdoutLogFile=".\logs\stdout"
    hostingModel="inprocess">
</aspNetCore>

The following sample aspNetCore element configures stdout logging at the relative path .\log\by Confirm that the AppPool user identity has permission to write to the path provided.

Any folders in the path (logs in the preceding example) are created by the module when the log file is created. The app pool must have write access to the location where the logs are written (use IIS AppPool\{APP POOL NAME} to provide write permission, where the placeholder {APP POOL NAME} is the app pool name).

When you publish using Visual Studio and a pipeline, the web.config that is added by default is different.

When you deploy from a pipeline, it also adds WEBSITE_RUN_FROM_PACKAGE to the Azure resource's Configuration -> ApplicationSettings, with a value of 1. You can't even use KUDU to manually edit the web.config with this configured.

To update the web.config, set the above config setting to 0 but it also changes the value of stdoutLogFile from ".\logs\stdout" to "\?%home%\LogFiles\stdout" automatically. If you have logging enabled, you will also notice the Logs folder at the wwwroot.

  • The information about the `WEBSITE_RUN_FROM_PACKAGE` configuration is helpful. Thank you. I'm not seeing the value of `stdoutLogFile` automatically updated when updating the `WEBSITE_RUN_FROM_PACKAGE` config. I tried redeploying from the pipeline but the value is set back to 1. I tried deleting the `WEBSITE_RUN_FROM_PACKAGE` config and updating the AzureRmWebAppDeployment@4 task to specify Web Deploy as the deployment method so the value would not be added but `stdoutLogFile` value is still ".\logs\stdout" – IamMike Nov 22 '21 at 16:41