473,761 Members | 2,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to override Debug.Writeline ?

Hi!

How can I override "Debug.Writelin e("Message")" so that will not show
that msg in Debug window, but wrote it to a file. I already have a code
to write to a file but I would like to use just "Debug" class (same
name) for that. Inside of that code I will decide if I will wrote that
message to debug window or to a file. I would like to use that two
options:
-Debug.Writeline ("Message", 1) '1 is integer argument from 0-9
-Debug.Writeline ("Message")

I would like to put that code in regular modul or class so I can call
then that method from any form or general procedure in application.
Im pretty sure that this can be done but don't know how. Can you help
me with that?

Billy

Nov 21 '05 #1
5 3402
Hi Billy,

you never can override the Debug class (it's sealed).

Only add a TextWriterTrace Listener to the Debug.Listeners .

Roland

"Billy" wrote:
Hi!

How can I override "Debug.Writelin e("Message")" so that will not show
that msg in Debug window, but wrote it to a file. I already have a code
to write to a file but I would like to use just "Debug" class (same
name) for that. Inside of that code I will decide if I will wrote that
message to debug window or to a file. I would like to use that two
options:
-Debug.Writeline ("Message", 1) '1 is integer argument from 0-9
-Debug.Writeline ("Message")

I would like to put that code in regular modul or class so I can call
then that method from any form or general procedure in application.
Im pretty sure that this can be done but don't know how. Can you help
me with that?

Billy

Nov 21 '05 #2
"Billy" <ab****@yahoo.c om> schrieb:
How can I override "Debug.Writelin e("Message")" so that will not show
that msg in Debug window, but wrote it to a file. I already have a code
to write to a file but I would like to use just "Debug" class (same
name) for that.


Receiving debug and trace messages in a form by adding a listener
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=debugtracel istener&lang=en >

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3
So that mean that I cannot use the same command which will do/show
something else. For example:
I wrote Debug.Writeline ("MessageX") --> and I got for example in debug
window or in a file "You wrote MessageX"

??

Nov 21 '05 #4
Billy,
You can use Debug.WriteLine , however you need to modify the Debug.Listeners
collection to do it.

You can modify the Debug.Listeners collection either in code or via your
app.config file.

I normally use the app.config, for example, try the following in your
app.config:

<configuratio n>
<system.diagnos tics>
<trace autoflush="true " indentsize="0">
<listeners>
<remove name="Default" />
<add name="MyListene r"
type="System.Di agnostics.TextW riterTraceListe ner, Version,
Culture, PublicKeyToken"
initializeData= "MyListener.log "/>
</listeners>
</trace>
</system.diagnost ics>
</configuration>

Which should remove the default TraceListener (the one going to the Debug
Window) and adds a new TraceListener that writes to the MyListener.log file.
The following provide a good introduction to TraceListeners:

http://msdn.microsoft.com/msdnmag/is...r/default.aspx

http://msdn.microsoft.com/library/de...eListeners.asp

http://msdn.microsoft.com/library/de...erselement.asp

http://msdn.microsoft.com/library/de...erselement.asp

http://msdn.microsoft.com/library/de...oveelement.asp

http://msdn.microsoft.com/library/de...ClassTopic.asp

Hope this helps
Jay
"Billy" <ab****@yahoo.c om> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
So that mean that I cannot use the same command which will do/show
something else. For example:
I wrote Debug.Writeline ("MessageX") --> and I got for example in debug
window or in a file "You wrote MessageX"

??

Nov 21 '05 #5
Thanks to all for help. I will try Jay's solution.

Regards,
Billy

Nov 21 '05 #6

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

Similar topics

16
1742
by: ssg31415926 | last post by:
Could someone explain the implications of the differences between using 'new' and 'override' on a member declaration, please. I checked out MSDN but it's not exactly written for the beginner. E.g. on Name Hiding, it starts with this: "The scope of an entity typically encompasses more program text than the declaration space of the entity." That whizzing sound you're hearing is it going over my head! SSG
0
4114
by: han.phony | last post by:
Hi, I am trying to intercept the message sent back by winmm.dll's mciSendString method when playback is finished. I tried to override the WndProc in the form but I didn't get/intercept the message, here is the code fragment: public const int MM_MCINOTIFY = 953; public const int MM_NOTIFY_ABORTED = 4; public const int MCI_NOTIFY_FAILURE = 8; public const int MCI_NOTIFY_SUCCESSFUL = 1; public const int MCI_NOTIFY_SUPERSEDED = 2;
5
4534
by: Marcel Hug | last post by:
Hi NG ! I'm new in C# and I'm reading a book about the fundamentals and concepts. In the chapter Methods it's written to use virtual, if i would like to override the method in a subclass. This I've to do by using override. It's also written, that's possible to "hide" the base class method by using the new key word. Because I've already written some C# code and I didn't know anything
3
1792
by: Publicjoe | last post by:
OK Folks, I am one confused puppy. Can someone please explain what the difference is and when to use each. I have a form with a button dropped onto it. Without actually doing anything to the button, I next add the following code: protected override void OnKeyDown(KeyEventArgs e) { System.Diagnostics.Debug.WriteLine(e.KeyCode.ToString()); base.OnKeyDown(e);
2
1436
by: Publicjoe | last post by:
OK Try again Can someone please explain what the difference is and when to use each. I have a form with a button dropped onto it. Without actually doing anything to the button, I next add the following code to the form: protected override void OnKeyDown(KeyEventArgs e) { System.Diagnostics.Debug.WriteLine(e.KeyCode.ToString());
2
4387
by: Fredo | last post by:
I'm going to try to post this without having to paste in hundreds of lines of code. I'm trying to override IInternetSecurityManager. I'm taking sort of a minimalist approach and adding code as I take each step because I'm not 100% sure about what I'm doing here. First of all, I've created a WebBrowser class. It is defined as: public class WebBrowser : AxSHDocVw.AxWebBrowser,
8
2833
by: Phil Jollans | last post by:
Hi, I am having difficulty overriding the ToString() method of CultureInfo using Visual Studio 2005. Exactly the same code works fine with Visual Studio .NET 2003. What I am doing is adding objects which are derived from CultureInfo to a ListBox. I want the language name to be displayed in the native language, so I override the ToString() method to access the CultureInfo.NativeName
2
1326
by: Your_Persona | last post by:
Is there a way to get effect1 with the method in effect2? ///////////////////////////////////////////////////////////////////////////////////////////// using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program
0
1800
by: BA | last post by:
I posted on this once before and could not get a solution, I am hoping someone can help. I have a very strange code debug behavior that I cannot make heads or tails of: I have c# code being executed in BizTalk assemblies which is repeating debug statements. I tried debug.flush() and debug.close() which did not solve the problem. In my BizTalk process I call a static method:
0
9522
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10111
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9902
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9765
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7327
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6603
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3866
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.