OK, here’s a good one (I think) – I’m working on an application with lots (far too many) dependency dlls, created by a team of developers. I’m trying to debug just one assembly, but the console output is ‘polluted’ by the Console.WriteLines and Debug.WriteLines left scattered around the code.
Is there anyway I can work out exactly which assembly a given line is coming from, so I can get the author to clean up their source?
UPDATE If you’re also experiencing this kind of issue, note that there is another potential source of output messages which is any breakpoints with ‘When hit’ set to print a message. Having said which, this is a VERY cool feature, which can prevent the kind of problems I was having above.
Yes – replace
Console.Out. UseConsole.SetOutafter creating aTextWriterwhich not only dumps the requested data to the original console, but also dumps a stack trace (and timestamp, and the requested data) to a file.Here’s some code, adapted from Benjol’s answer:
(Note: you will want to adapt this code depending on whether you want a stack trace after each write, or after each writeline. In the code below, each char is followed by a stack trace!)
To use this for logging both
Console.WriteLineandDebug.WriteLine to a file, make calls like this as early as possible in your code:Note that this currently doesn’t also write to the original console. To do so, you’d need to have a second
TextWriter(for the original console) inStackTracingWriter, and write to both places each time. Debug will however continue to be written to the original console.