473,397 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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?

Nov 15 '05 #1
2 5283
"S. Han" wrote:
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
--
To mail me directly, remove the NO*SPAM parts in
NO***********@gmx.netNO*SPAM
Nov 15 '05 #2
"Andreas Müller" <me@privacy.net> wrote

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.
--
http://ManagedXLL.net/ | http://jens-thiel.de/ | http://QuantLib.net/
Replace MSDN with my first name when replying to my email address!
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: scsharma | last post by:
Hi, I am having trouble with following piece of code: Trace.Assert(args.Length >=1,"Invalid Argument list. Statement Date is mandatory input"); I expect the code to stop execution and exit...
11
by: David | last post by:
I am compiling C++ under both MacOsX and under Bloodshed Dev C++ on Windows XP. Because the console window disappears under Bloodshed when using the standard assert() via #include <cassert> I...
1
by: S. Han | last post by:
I use Trace.Assert() in my app.config, and I added <system.diagnostics> <assert assertuienabled="false" />... so that I could redirect the assertion failure to the console output. The problem...
0
by: Pete W | last post by:
I have a console application for which I have atttemped to use TextWriterTraceListener. The app uses System.Diagnostic I want to trace or debug to Console and also to file. code in Main()...
1
by: High and dRy | last post by:
Hello, I created a simple .NET C++ console application. And the Debug::Assert(false) statement is popping a message box in release version also. Any idea why ? Any complier settings I need to do...
5
by: martin | last post by:
Hi, The trace class seems to me to be very usefull however there are a few features of it that have to confused. I am using visual studio 2003. the IDE will not let me write ...
1
by: AJ | last post by:
How can I use Trace.Assert method? It says that 'Assert' is not a member of 'System.Web.TraceContext'. Please help. Thanks.
2
by: news.microsoft.com | last post by:
Hi all. If I wanted to write something so that, when an exception was thrown, and the stack unwound, the stack trace was captured with the values of the parameters (instead of just the parameter...
12
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I saw a couple of form of assert in code on Windows, 1. ASSERT; 2. assert; 3. _ASSERT; 4. _assert.
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.