473,657 Members | 3,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tracing

Hi

Does the class System.Diagnost ics.Trace use a singelton ?

I'm able to do this;
System.Diagnost ics.Trace.Write Line("test");

However, these give compiler errors;
System.Diagnost ics.Trace myTrace = new System.Diagnost ics.Trace; // A
new expression requires () or []
System.Diagnost ics.Trace myTrace = new System.Diagnost ics.Trace(); //
No constructors defined

So there can only be one Trace instance within a .NET application, is
that correct?

What would happen in the following situation. An main application has
a Logger class with 3-4 WriteXXX methods (a singelton class) that
formats the input in a specifc way and writes it to Trace.WriteLine
method that is setup to write to an ascii file. Then we have a
lightweight plugin that uses Trace::WriteLin e("...") without any
particular formating in the message and then writes data to the
OutputDebugStri ng. What will happen if the main application loads the
plugin?

I'm guessing it will affect the Trace behaviour - the plugin will
'lose' the OutputDebugStri ng property and instead send unformated
strings to main application log file.
Oct 29 '08 #1
1 1714
On Wed, 29 Oct 2008 00:27:21 -0700, RedLars <Li***********@ gmail.com>
wrote:
Hi

Does the class System.Diagnost ics.Trace use a singelton ?
The methods are static. I suppose internally it could be implemented as a
singleton, but I don't know why it would be. I haven't looked, but I
think it's more likely it's just effectively a plain, static class.
[...]
What would happen in the following situation. An main application has
a Logger class with 3-4 WriteXXX methods (a singelton class) that
formats the input in a specifc way and writes it to Trace.WriteLine
method that is setup to write to an ascii file. Then we have a
lightweight plugin that uses Trace::WriteLin e("...") without any
particular formating in the message and then writes data to the
OutputDebugStri ng. What will happen if the main application loads the
plugin?
That depends on how you've configured the tracing.

Personally, I find the tracing functionality in .NET to be unnecessarily
complicated. I have seen recommendations for Log4net, and you may want to
look into that. I haven't used it myself, but everyone else seems to
think it's much better. :)

If you do want to use the .NET trace stuff, it's helpful to keep in mind
that three different classes work together to control what actually goes
out: TraceListener (which does the actual logging), TraceSource (which
defines a particular association for specific trace output), and
TraceSwitch (which controls what tracing is enabled for a particular
source).

My recollection is that you can set things up so that your TraceListener
doesn't necessarily output stuff that's written using the plain Trace
methods. By adding it only to the listeners for a TraceSource, then only
when you output to that source will that listener write output. And of
course, the plug-in shouldn't have access to that source.

Unfortunately, the docs mostly assume that you will be using an .config
file to control tracing. I found the documentation to be very unhelpful
for controlling tracing programmaticall y. But I was able to get things
set up the way I wanted through some trial and error and a bit of
guesswork. If I could remember more details off the top of my head, I'd
post them now, but I don't. Sorry. I can probably dig up some sample
code I wrote if you decide you want to keep using the .NET trace stuff and
are having trouble (though, even what I did come up with wasn't all that
complicated...f or advanced use of the .NET trace mechanism you'll need a
better resource than me).

Pete
Oct 29 '08 #2

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

Similar topics

2
1692
by: Trace User | last post by:
Hello, I have a design question regarding Tracing and Trace Switches. I understand that Trace Switches can be configured through an application's .config file. When a switch is instantiated, the application automatically checks the configuration file for a matching named switch. If there's a match, the configuration parameters are set.
3
1708
by: Serge Rielau | last post by:
Hi SQL Procedure developers, As threatened in earlier posts the SQL PL Tracing facility is finally oot-and-aboot. SQL procedure tracing: Analyzing SQL procedure flow This article describes an API that allows for transparent tracing of SQL procedures as well as explicit tracing of non-SQL procedures in DB2 Universal Database (UDB) V8.2 for LUW. An example SQL interface to this API is provided, as well.
0
1261
by: Paul Ibison | last post by:
HI when I have a page which calls a component I want to do the following - tracing set to false on the pag tracing set to true in the componen tracing set to false in the page after the call to the component. This is so any further tracing calls are ignored However, I find that there are no tracing results. Can I do this sort of thing - perhaps I am missing something Regards Paul Ibiso
5
1575
by: Dabbler | last post by:
When I first start up an ASP.NET application with tracing enabled in web.config the first few pages show trace at bottom of the page but then at some point the pages return to normal with no trace information displayed. Can anyone tell me what might be causing the Trace to turn off? Thanks for any help with this ..NET 1.1 running on localhost
6
1656
by: serge calderara | last post by:
Dear all, I have an applicatin that generate a querry to an SQL server, then display results on a second webform. I try to see how tracing works, then I have notice that as soon as I implement tracing on the page, when I click on the BACK button of explorer I get a warning message that information of the page needs to be resend to be displayed ?
2
1752
by: deepukutty | last post by:
Hi all, I know tht we can do tracing in two ways.one in application level and the other is at Page level. I am able to see the details of trace either on the page itself or .../trace.axd page. I want to use maximum out of the available trace details . or let me put it like this.... tell me the actual scenario's where these trace details will be use ful and
0
1363
by: cnys | last post by:
We have an ASP.NET 2.0 (C#) app and we're trying to add tracing into it. The tracing functionality within .NET is great, but when we output this to a file, it's kind of sparse. So, we're looking for ideas on how to get more tracing info. output to our log file than what's currently output by calling the Write methods. Here are some snippets of what we're thinking of:
0
1039
by: GB | last post by:
All, There's a few messages around about the Environment.GetResourceString causing a "Resource lookup failed - infinite recursion detected." error but nothing detailed. I have a problem whereby I am changing the thread Culture Info from default (English) to a custom culture object (Welsh) in a .NET 1.1 ASPX page.
0
1330
by: rehto | last post by:
We have an ASP.NET 2.0 (C#) app and we want to enable tracing (see the code snippets below). The first time a user navigates to the app., the tracing works fine (the ASP.NET tracing appears on the screen and writes to a text file). The problem happens any subsequent time the app. is used--tracing doesn't happen. It's as if tracing just turns itself off. So, we only get tracing on the first time the app runs but never any other time. ...
0
8820
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...
0
8601
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...
0
7314
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
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
5630
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();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
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.