My apps logs structured (json) logs to STDOUT. When someone does something like Console.Write("Foo") it will mess up json parser and log pipeline will yell at me.
How to prevent anything but my logger output end up in STDOUT? Keep in mind that even if I remove all Console.Write occurances in my code, something may reside in one of multiple libraries I'm including in my product - debuging this is a nightmare.
I must log to the console, platform (kubernetes) requires it.
IMHO dealing with it in your code is prohibitively expensive. Nobody sane would print directly to
Consolein library, so unless you are dealing with extreme case the author of the closed-source library died, I would simply reach out to the author and point a bug in his/her code rather than change my code around it. Fixing the issue would benefit not only you, but everybody using the library including its author.