Skip to content

Conversation

@jonathanpeppers
Copy link
Member

Context: #5494
Context: #5241
Fixes: #5435

We added --dsrouter switch to both dotnet-trace and dotnet-gcdump, which runs dotnet-dsrouter as a child process.

Many of dotnet-dsrouter's console messages are pretty useful for developers, but we are simply ignoring them:

private static async Task ReadAndIgnoreAllStreamAsync(StreamReader streamToIgnore, CancellationToken cancelToken)
{
    Memory<char> memory = new char[4096];
    while (await streamToIgnore.ReadAsync(memory, cancelToken).ConfigureAwait(false) != 0)
    {
    }
}

To make this a bit more useful, we now log the output to either Console.Out or Console.Error where appropriate.

If we simply did:

string line;
while ((line = await streamToRead.ReadLineAsync(cancelToken).ConfigureAwait(false)) != null)
{
    output.WriteLine(line);
}

This would work fine, but we'd lose all coloring.

dotnet-dsrouter uses SimpleConsoleFormatter to colorize its output:

https://github.com/dotnet/runtime/blob/aadcceeb03ce0ecbc2ad645de0feb10189daa64c/src/libraries/Microsoft.Extensions.Logging.Console/src/SimpleConsoleFormatter.cs#L163-L199

So, for now, a very simple solution is to check the known prefixes and add coloring. This looks to have a pretty good result.

I also dropped the duplicate message:

WARNING: dotnet-dsrouter is a development tool not intended for production environments.

Now that we print all of dotnet-dsrouter's output, we can handle this case and color it yellow.

image

Context: #5494
Context: #5241
Fixes: #5435

We added `--dsrouter` switch to both `dotnet-trace` and
`dotnet-gcdump`, which runs `dotnet-dsrouter` as a child process.

Many of `dotnet-dsrouter`'s console messages are pretty useful for
developers, but we are simply ignoring them:

    private static async Task ReadAndIgnoreAllStreamAsync(StreamReader streamToIgnore, CancellationToken cancelToken)
    {
        Memory<char> memory = new char[4096];
        while (await streamToIgnore.ReadAsync(memory, cancelToken).ConfigureAwait(false) != 0)
        {
        }
    }

To make this a bit more useful, we now log the output to either
`Console.Out` or `Console.Error` where appropriate.

If we simply did:

    string line;
    while ((line = await streamToRead.ReadLineAsync(cancelToken).ConfigureAwait(false)) != null)
    {
        output.WriteLine(line);
    }

This would work fine, but we'd lose all coloring.

`dotnet-dsrouter` uses `SimpleConsoleFormatter` to colorize its output:

https://github.com/dotnet/runtime/blob/aadcceeb03ce0ecbc2ad645de0feb10189daa64c/src/libraries/Microsoft.Extensions.Logging.Console/src/SimpleConsoleFormatter.cs#L163-L199

So, for now, a very simple solution is to check the known prefixes and
add coloring. This looks to have a pretty good result.

I also dropped the duplicate message:

    WARNING: dotnet-dsrouter is a development tool not intended for production environments.

Now that we print all of `dotnet-dsrouter`'s output, we can handle
this case and color it yellow.
@jonathanpeppers jonathanpeppers requested a review from a team as a code owner July 21, 2025 20:20
Copy link
Member

@tommcdon tommcdon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@jonathanpeppers jonathanpeppers enabled auto-merge (squash) July 21, 2025 20:59
@jonathanpeppers jonathanpeppers merged commit 7906474 into main Jul 21, 2025
19 checks passed
@lateralusX
Copy link
Member

@jonathanpeppers Did you test how this works with dotnet-trace? Since it uses the console differently to track progress, having log messages added to the console once it starts to collect might have side effects on the progress logging. Did you have a look on how it behaves?

@jonathanpeppers
Copy link
Member Author

@lateralusX I think dotnet-trace is working ok:

image

@jonathanpeppers jonathanpeppers deleted the dev/peppers/log-dsrouter-output branch July 22, 2025 14:23
@jonathanpeppers jonathanpeppers self-assigned this Jul 28, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Aug 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add additional log messages for dotnet trace collect --dsrouter

4 participants