Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log Output Does Not Work for Application Paths When Using ParallelApplicationPipelinesExtensions #190

Open
haacked opened this issue Oct 31, 2019 · 2 comments

Comments

@haacked
Copy link

haacked commented Oct 31, 2019

When using ParallelApplicationPipelinesExtensions, log messages originating from an application path do not show in the console.

Repro Steps

  1. Clone https://github.com/WebApiContrib/WebAPIContrib.Core/
  2. Make the following edit to WelcomeService.cs
public class WelcomeService : IGreetService
{
    readonly ILogger<WelcomeService> _logger;

    public WelcomeService(ILogger<WelcomeService> logger)
    {
        _logger = logger;
    }

    public string Greet()
    {
        _logger.LogError("Error Will Robinson!");
        return "Welcome!";
    }
}
  1. Run the app using dotnet run from the console.
  2. Visit https://localhost:5001/welcome-branch in your browser.

Expected Behavior

I expect to see the "Error Will Robinson" message in the console output.

Actual Behavior

I only see log messages from ASP.NET Core itself.

Extra Information

Note that if you change the Main method in Program.cs like so...

public static void Main(string[] args)
{
    var host = BuildWebHost(args);
    var logger = host.Services.GetRequiredService<ILogger<Program>>();
    logger.LogInformation("This log message works.");
    host.Run();
}

That log message works. It seems to me that the logging services or configuration are not carried over to the application paths.

/cc @filipw

@haacked
Copy link
Author

haacked commented Oct 31, 2019

Note that I also tested this on ASP.NET Core 3.0 and it still doesn't work.

@haacked
Copy link
Author

haacked commented Nov 4, 2019

Ok, I figured out a fix for my scenario, but it applies to asp.net core 3.0. I haven't investigated a asp.net core 2* fix.

Here's the change to make in https://github.com/WebApiContrib/WebAPIContrib.Core/blob/master/src/WebApiContrib.Core/ParallelApplicationPipelinesExtensions.cs

- var webHost = new WebHostBuilder().
+ var webHost = Host.CreateDefaultBuilder().
      ConfigureServices(s => {
            s.AddSingleton<IServer, DummyServer>();
      }).
      ConfigureServices(servicesConfiguration).
-     UseStartup<EmptyStartup>().
+     ConfigureWebHostDefaults(wh => wh.UseStartup<EmptyStartup>()).
      Build();

  var serviceProvider = webHost.Services;
- var serverFeatures = webHost.Features;
+ var serverFeatures = new FeatureCollection();

This sets up logging correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant