dotnet / dotnet/aspnetcore

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

Open
#14,988 20 comments 1 reaction 0 assignees View on GitHub
affected-very-few area-networking enhancement feature-iis severity-nice-to-have
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### 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:

```

















```
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: [https://github.com/aspnet/AspNetCore.Docs/issues/15080](https://github.com/aspnet/AspNetCore.Docs/issues/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:





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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.