-
-
Notifications
You must be signed in to change notification settings - Fork 109
Enhance DefaultLogger with extensibility features #4131
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
Conversation
…ation for custom loggers
Code Review: Enhance DefaultLogger with extensibility featuresThank you for this PR! This is a well-thought-out enhancement that adds valuable extensibility points to the DefaultLogger class. Here's my detailed feedback: ✅ Strengths
🔍 Code Quality ObservationsPerformance Considerations (TUnit.Core/Logging/DefaultLogger.cs)
Thread Safety Concerns
Missing Async Consistency
🧪 Testing
📝 Documentation
🎯 SummaryThis PR adds valuable extensibility features to TUnit's logging system. The main areas for improvement are:
The changes align well with TUnit's philosophy of being modern and extensible. Once the performance and thread-safety concerns are addressed, this will be a solid enhancement! 🔧 Action ItemsHigh Priority:
Medium Priority:
Low Priority:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances the DefaultLogger class with extensibility features to allow custom logger implementations. It also updates documentation to remove specific performance benchmark numbers in favor of more general language that won't become outdated.
Key changes:
- Made
DefaultLoggerextensible by exposing virtual methods and a protected Context property - Refactored duplicated output writing logic into reusable virtual methods
- Updated documentation with extensibility examples and removed hard-coded benchmark numbers
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| TUnit.Core/Logging/DefaultLogger.cs | Added protected Context property and three virtual methods (GenerateMessage, WriteToOutput, WriteToOutputAsync) to enable custom logger implementations; refactored duplicate output logic |
| docs/docs/customization-extensibility/logging.md | Added comprehensive documentation on custom loggers with practical examples showing how to extend DefaultLogger for custom formatting and output destinations |
| docs/docs/migration/xunit.md | Removed specific "1.3x faster" claim in favor of general performance improvement statement |
| docs/docs/migration/nunit.md | Removed specific "1.2x faster" claim in favor of general performance improvement statement |
| docs/docs/migration/mstest.md | Removed specific "1.3x faster" claim in favor of general performance improvement statement |
| docs/docs/advanced/performance-best-practices.md | Removed specific "11.65x faster" claim for AOT in favor of "significant speed improvements" |
| TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.Net4_7.verified.txt | Updated public API snapshot to reflect new protected members in DefaultLogger |
| TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.DotNet8_0.verified.txt | Updated public API snapshot to reflect new protected members in DefaultLogger |
| TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.DotNet9_0.verified.txt | Updated public API snapshot to reflect new protected members in DefaultLogger |
| TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.DotNet10_0.verified.txt | Updated public API snapshot to reflect new protected members in DefaultLogger |
| protected virtual void WriteToOutput(string message, bool isError) | ||
| { | ||
| if (isError) | ||
| { | ||
| context.ErrorOutputWriter.WriteLine(message); | ||
| GlobalContext.Current.OriginalConsoleError.WriteLine(message); | ||
| } | ||
| else | ||
| { | ||
| context.OutputWriter.WriteLine(message); | ||
| GlobalContext.Current.OriginalConsoleOut.WriteLine(message); | ||
| } | ||
| } |
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The WriteToOutput method references the 'context' parameter directly instead of using the protected Context property. This creates an inconsistency since a protected Context property was added specifically for derived classes to access the context. Consider using 'Context' instead of 'context' for consistency with the extensibility design.
| protected virtual async ValueTask WriteToOutputAsync(string message, bool isError) | ||
| { | ||
| if (isError) | ||
| { | ||
| await context.ErrorOutputWriter.WriteLineAsync(message); | ||
| await GlobalContext.Current.OriginalConsoleError.WriteLineAsync(message); | ||
| } | ||
| else | ||
| { | ||
| await context.OutputWriter.WriteLineAsync(message); | ||
| await GlobalContext.Current.OriginalConsoleOut.WriteLineAsync(message); | ||
| } | ||
| } |
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The WriteToOutputAsync method references the 'context' parameter directly instead of using the protected Context property. This creates an inconsistency since a protected Context property was added specifically for derived classes to access the context. Consider using 'Context' instead of 'context' for consistency with the extensibility design.
No description provided.