Skip to content

Unable to redirect Console output (logging) to text (stdoutLogFile) file? #14988

@bdcoder2

Description

@bdcoder2

Describe the bug

When trying to redirect Console output to a text file, the stdoutLogFile is created, but is always empty.

The following settings are present in the projects ( ASP.NET Core Web Application) web.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <remove name="aspNetCore" />
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true" stdoutLogFile="D:\temp\website3_log" hostingModel="inprocess">
       <handlerSettings>
          <handlerSetting name="debugFile" value="D:\\temp\\website3_debug_log" />
          <handlerSetting name="debugLevel" value="FILE,INFO" />
       </handlerSettings>
      <environmentVariables>
        <environmentVariable name="ASPNETCORE_HTTPS_PORT" value="44383" />
        <environmentVariable name="COMPLUS_ForceENC" value="1" />
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
      </environmentVariables>
    </aspNetCore>
  </system.webServer>
</configuration>

The debugFile is created and log entries are present without issue.

The stdoutLogFile is created, but remains empty.

Questions:

  • WHY is the stdoutLogFile always empty? It appears that when Console.WriteLine( "this should be in the log file" ) statements are executed within code, the WriteLine method is NOT redirecting output to the stdoutLogFile.

To Reproduce

Steps to reproduce the behavior:

  1. Using Visual Studio
  2. Click on "Create a new project"
  3. Select ASP.NET Core Web Application -> Next
  4. Enter project name, Location, Solution Name -> Create
  5. Add web.config to the project and set the stdoutLogEnabled="true"
  6. Set the stdoutLogFile attribute to the path of the log file.

Expected behavior

When Console.WriteLine() statements are executed, it is expected that the Console output is redirected to the stdoutLogFile file (or, at least one ASSUME's that would be the case -- can this be confirmed anywhere in the docs? -- I have yet to find anything!!).

Additional context

Also looking for details with regard to the schema of the following files:

  • web.config - where do we find the complete schema? Where do we find the complete schema that explains all valid entries that may appear in this file and the effect of each entry.

  • launchsettings.json - again, where do we find the complete schema that explains all valid entries that may appear in this file and the effect of each entry.

  • This issue was raised within the documentation at: Console log redirection needs working example AspNetCore.Docs#15080

Finally, not sure if this would be possible, but a more consistent approach to Console logging (redirection) might be to include a "handler" for Console output, for example:

   <handlerSettings>
      <handlerSetting name="debugFile" value="D:\\temp\\website3_debug_log" />
      <handlerSetting name="debugLevel" value="FILE,INFO" />
      <handlerSetting name="consoleFile" value="D:\\temp\\website3_console_log" />
   </handlerSettings>

Adding a handler for Console output would be more consistent than the stdoutLogFile and stdoutLogEnabled attributes on the aspNetCore node.

Metadata

Metadata

Assignees

No one assigned

    Labels

    affected-very-fewThis issue impacts very few customersarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-iisIncludes: IIS, ANCMseverity-nice-to-haveThis label is used by an internal tool

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions