Trace.Assert to console

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • S. Han

    #1

    Trace.Assert to console

    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?





  • Andreas Müller

    #2
    Re: Trace.Assert to console

    "S. Han" wrote:
    [color=blue]
    > 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?
    >[/color]

    Hi,

    implement a class derived from System.Diagnost ics.DefaultTrac eListener.
    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("Defaul t");
    Trace.Listeners .Remove("Defaul t");

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

    HTH,
    Andy
    --
    To mail me directly, remove the NO*SPAM parts in
    NO*SPAMxmen40@g mx.netNO*SPAM

    Comment

    • Jens Thiel

      #3
      Re: Trace.Assert to console

      "Andreas Müller" <me@privacy.net > wrote[color=blue]
      >
      > if you wish to totally redirect the Assertion to your trace listener,
      > remove the default listener:
      > Debug.Listeners .Remove("Defaul t");
      > Trace.Listeners .Remove("Defaul t");[/color]

      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.diagnos tics>
      <assert assertuienabled ="false" logfilename="c: \TEMP\Debug.log " />
      </system.diagnost ics>

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


      Jens.


      --
      http://ManagedXLL.net/ | http://jens-thiel.de/ | http://QuantLib.net/
      Replace MSDN with my first name when replying to my email address!


      Comment

      Working...