Skip to content

Clarify how to capture logs from tests in .NET Aspire documentation #4252

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 12, 2025

This PR addresses the missing information about capturing logs from .NET Aspire tests by adding comprehensive documentation and code examples.

Changes Made

Enhanced Documentation

  • Added a new "Capture logs from tests" section to docs/testing/write-your-first-test.md
  • Explained how to use the AddLogging method on the service collection
  • Documented the need for explicit log filter configuration since appsettings.json isn't replicated in test projects
  • Provided recommendations for popular logging packages for each testing framework

Code Examples

  • Created complete LoggingTest.cs examples for xUnit, NUnit, and MSTest frameworks
  • Added proper package references for Microsoft.Extensions.Logging.Console
  • Updated the existing xUnit IntegrationTest1.cs comment to reference the new logging guidance
  • All code snippets build successfully and demonstrate proper logging configuration

Key Technical Details Covered

  • How to configure logging providers using builder.Services.AddLogging()
  • Setting appropriate log filters to reduce noise from infrastructure components:
    builder.Services.AddLogging(logging => logging
        .AddConsole()
        .AddFilter("Default", LogLevel.Information)
        .AddFilter("Microsoft.AspNetCore", LogLevel.Warning)
        .AddFilter("Aspire.Hosting.Dcp", LogLevel.Warning));
  • Framework-specific logging provider package recommendations

The solution provides clear, actionable guidance that makes it much easier for developers to capture and view logs during .NET Aspire test execution, addressing the confusion mentioned in the original issue.

Fixes #2096.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • aka.ms
    • Triggering command: curl -I -sSL --retry 5 --retry-delay 2 --connect-timeout 15 REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Internal previews

📄 File 🔗 Preview link
docs/testing/write-your-first-test.md Write your first .NET Aspire test

…t frameworks

Co-authored-by: IEvangelist <7679720+IEvangelist@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Clarify how to capture logs from tests Clarify how to capture logs from tests in .NET Aspire documentation Aug 12, 2025
Copilot finished work on behalf of IEvangelist August 12, 2025 18:46
@Copilot Copilot AI requested a review from IEvangelist August 12, 2025 18:46
Copy link
Contributor

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 issues. Other issues are also a high priority. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

@IEvangelist IEvangelist marked this pull request as ready for review August 15, 2025 15:58
Copy link
Contributor

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 issues. Other issues are also a high priority. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

@IEvangelist IEvangelist requested a review from adegeo August 15, 2025 16:05
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

Successfully merging this pull request may close these issues.

Clarify how to capture logs from tests
2 participants