Trace.Assert to console

  • Thread starter Thread starter S. Han
  • Start date Start date
S

S. Han

I use Trace.Assert() through out my app and it's such a great way to debug a
program. My question is is there any way to redirect the assertion pop-up to
the command line output in my console application?
 
S. Han said:
I use Trace.Assert() through out my app and it's such a great way to
debug a program. My question is is there any way to redirect the
assertion pop-up to the command line output in my console
application?

Hi,

implement a class derived from System.Diagnostics.DefaultTraceListener.
override the Fail() method.

Then add tan instance of this class to the Trace Listeners collection:
Trace.Listeners.Add(new YourListener());

if you wish to totally redirect the Assertion to your trace listener,
remove the default listener:
Debug.Listeners.Remove("Default");
Trace.Listeners.Remove("Default");

A nice Article to that topic is here:
<http://www.codeproject.com/csharp/assert.asp?target=>

HTH,
Andy
 
Andreas Müller said:
if you wish to totally redirect the Assertion to your trace listener,
remove the default listener:
Debug.Listeners.Remove("Default");
Trace.Listeners.Remove("Default");

Andreas,

are there really two trace listener collections? I always thought that Debug
and Trace share the same collection.

It is also possible to disable the assert pop-up by adding

<system.diagnostics>
<assert assertuienabled="false" logfilename="c:\TEMP\Debug.log" />
</system.diagnostics>

to the configuration file. You can also add your own <listeners> section
here.


Jens.
 
Back
Top