dotnet / dotnet/aspnetcore

Allow configuring W3CLogging to write to stdout

Open
#42,489 8 comments 15 reactions 0 assignees View on GitHub
area-networking Needs: Design
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

I am trying to configure the W3CLogging to write to stdout instead of a file on disk, since this is a best practice when running applications in a Docker container. I tried the following, but it doesn't quite work because it ultimately is trying to write to /dev/stdout/w3clog-20220629.0000.txt, for example, which isn't a valid location on Linux:

```
builder.Services.AddW3CLogging(logging =>
{
logging.LogDirectory = "/dev/stdout";
});
```

Is there some way to have the W3C logs write to stdout instead of a file on disk?

### Describe the solution you'd like

It seems like if we could configure the W3CLogger to not rotate files but always write to a specific "file", that would solve this for us. Something like this, perhaps:

```
builder.Services.AddW3CLogging(logging =>
{
// proposed: set a static file name that doesn't automatically append dates or rotate
logging.StaticFileName = "/dev/stdout";
});
```

By setting `StaticFileName`, this would override the normal behavior you get when setting `FileName` and `LogDirectory`, and would ignore `RetainedFileCountLimit` and `FileSizeLimit`. New logs would just be written directly to whatever file you defined by StaticFileName, which in our case could be /dev/stdout, which is the standard Linux "file" that represents stdout.

If this idea doesn't really pan out, alternatively, could a separate "mode" be added to the W3CLogger that just tells it to write to stdout? Perhaps something like this:

```
builder.Services.AddW3CLogging(logging =>
{
// proposed: set the mode to write to stdout
logging.WriteToStdOut = true;
});
```

### Additional context

_No response_

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.