Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9054049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:35:05+00:00 2026-06-16T13:35:05+00:00

I have the simple function let OutputDebugToConsole () = new System.Diagnostics.TextWriterTraceListener(System.Console.Out) |> System.Diagnostics.Debug.Listeners.Add |>

  • 0

I have the simple function

let OutputDebugToConsole () =
    new System.Diagnostics.TextWriterTraceListener(System.Console.Out)
        |> System.Diagnostics.Debug.Listeners.Add |> ignore

to redirect the debug output from Debug.WriteLine to the console.

I wish to have the debug output in a different colour, by setting Console.ForegroundColor to gray, for example. Obviously the colour needs to be reset after each writing for normal text to be written in standard colours. My idea is to pass a different TextWriter that decorates the Write method.

First, is this a sensible way of thinking about the problem? Second, to do this would I need to rewrite all methods of my TextWriter or is there a different way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T13:35:06+00:00Added an answer on June 16, 2026 at 1:35 pm

    Console.ForegroundColor has both a property getter and setter so it is technically possible to simply store the old color, assign it, write and restore the old color.

    It is however not thread-safe to do so. Another thread may also use Console.Write and assign the ForegroundColor property to get its own preferred color. That’s a race, your logger may end up writing with the color selected by the other thread. And the other way around. There’s a lock that prevents both threads writing text to the console and get their output intermingled, but it is taken too late. There is no simple way to solve that, other than having your logger using pinvoke so that it doesn’t need to use ForegroundColor at all.

    That’s a fugly little detail if there ever was one. That’s why it is usually better to use a logging library that takes care of these nasty little details. NLog for example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

let's say I have a simple javascript like so: $(document).ready(function(){ if(login == 1) {
Let's say I have some simple Javascript like: <script> var hello = function(){ alert(Hello
Let's say I have the following, very simple block of code: <script> function hasVal(field)
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
I have a simple f# quick sort function defined as: let rec qsort(xs:List<int>) =
Let's have the following simple function (the body of my function is more complicated
Let's say we have a particularly simple function like import scipy as sp def
Let's say I have a simple function like this: public static string randomthing(string var1)
Let's say I have a simple class called WebsterDictionary that has a function that
I have a simple function as the following: static Task<A> Peirce<A, B>(Func<Func<A, Task<B>>, Task<A>>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.