[dotnet] Make internal console writer more flexible via taking TextWriter only#15346
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||
RenderMichael
left a comment
There was a problem hiding this comment.
Having the TextWriterHandler is a good idea, however the existing ConsoleLogHandler is used by users. We would need to keep a type that just points to the text writer handler:
public class ConsoleLogHandler : TestWriterHandler(Console.Error);Additionally, TestWriterHandler(Console.Error) is not the same as ConsoleLogHandler if a user uses the Console.SetError method. The current code would point to whatever the new Console.Error pointed to, but this PR would still point to the old sink.
True, and it is still good. As a low-level library we want to give user a power. Since this is "internal/advanced" thing, I am OK with this behavior.
OK, let's keep it and proceed via standard deprecation policy. Thank you, it is really better than just break. |
User description
Consoleis an output. We can be more extendable/abstract/generic.Motivation and Context
Taking minimal required.
Types of changes
Checklist
PR Type
Enhancement
Description
Replaced
ConsoleLogHandlerwithTextWriterHandlerfor flexibility.Updated
LogContextManagerto useTextWriterHandler.Modified logging tests to reflect the new handler.
Improved abstraction by utilizing
TextWriterfor log output.Changes walkthrough 📝
LogContextManager.cs
Refactored LogContextManager to use TextWriterHandlerdotnet/src/webdriver/Internal/Logging/LogContextManager.cs
ConsoleLogHandlerwithTextWriterHandler.GlobalContextinitialization to use the new handler.AsyncLocalinitialization syntax.TextWriterHandler.cs
Introduced TextWriterHandler for flexible log outputdotnet/src/webdriver/Internal/Logging/TextWriterHandler.cs
ConsoleLogHandlertoTextWriterHandler.Console.Errorwith aTextWriterparameter.TextWriter.LogTest.cs
Updated logging tests for TextWriterHandlerdotnet/test/common/Internal/Logging/LogTest.cs
TextWriterHandlerinstead ofConsoleLogHandler.