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

Clarify how to capture logs from tests #2096

Open
afscrome opened this issue Nov 15, 2024 · 0 comments
Open

Clarify how to capture logs from tests #2096

afscrome opened this issue Nov 15, 2024 · 0 comments
Assignees

Comments

@afscrome
Copy link

Type of issue

Missing information

Description

The docs don't mention how to get logs out of tests. There is a very brief comment that shows up in the xunit code sample, but it doesn't show

        // To output logs to the xUnit.net ITestOutputHelper, 
        // consider adding a package from https://www.nuget.org/packages?q=xunit+logging

It took me quite a while to work out that I was meant to use the AddLogging method on the services, and even longer to work out I needed to configure some default log filters as the appsettings.json from the application under test wasn't being replicated into the test projects.

      appHost.Services.AddLogging(x => x
            .AddNUnit() // https://www.nuget.org/packages/Extensions.Logging.NUnit
            .AddFilter("Default", LogLevel.Information)
            .AddFilter("Microsoft.AspNetCore", LogLevel.Warning)
            .AddFilter("Aspire.Hosting.Dcp", LogLevel.Warning)
      );

Page URL

https://learn.microsoft.com/en-us/dotnet/aspire/testing/write-your-first-test

Content source URL

https://github.com/dotnet/docs-aspire/blob/main/docs/testing/write-your-first-test.md

Document Version Independent Id

493680b6-598d-1d8c-6e0e-f54286ae77e0

Article author

@IEvangelist

@IEvangelist IEvangelist self-assigned this Nov 21, 2024
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

2 participants