How to show a console window when debugging a C# app through WSL in Visual Studio?
Asked Answered
C

1

15

I've followed the instructions shown here to get WSL running, and I can successfully debug my C# application on Windows in a Linux environment.

The problem is that by default, there is no console shown for a Console App if I run through WSL. The VS Immediate window is functional, so I can see the output of my application, but I can't use Console.ReadLine() for example.

Any help with a visual studio setting, or a programmatic way to allocate a console in WSL during runtime is appreciated.

Cordite answered 6/4, 2022 at 14:37 Comment(1)
Duplicate of #70687409Lactone
D
1

You can try using a method overload against the OpenTelemery package. The AddConsoleExporter should help with showing all your logs in the console window.

Below is an example of how it can be leveraged:

services.AddServiceTelemetry(
serviceName: serviceName,
configureTracer: providerBuilder => providerBuilder

     // Enable for local debugging
     .AddConsoleExporter()
    .AddSource(sourceName)
    .SetErrorStatusOnException(true)
    .AddAspNetCoreInstrumentation((options) =>
    {
        options.EnrichWithHttpRequest = (activity, req) => ASPNetCoreExtension.EnrichHttpRequest(activity, req);
        options.EnrichWithHttpResponse = (activity, res) => ASPNetCoreExtension.EnrichHttpResponse(activity, res);
        options.EnrichWithException = (activity, ex) => ASPNetCoreExtension.EnrichHttpException(activity, ex);
    }));

As shown above, you can use the AddAspNetCoreInstrumentation method to further enrich your logs. Note that ASPNetCoreExtension.EnrichHttpRequest methods are from my custom implementation code.

Deserved answered 18/4 at 4:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.