473,568 Members | 2,905 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trace & Config Files???

Hi,

I'm having trouble setting up a config file based trace switch & listener. I added an application config file to my console based C# program using the "Add New Application Config File" button from solution explorer. My config file is composed of the following, which is almost a verbatum cut & paste from MSDN help:

---------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<system.diagnos tics>
<switches>
<add name="mySwitch" value="3" />
</switches>
<trace autoflush="true " indentsize="2">
<listeners>
<add name="myListene r"
type="System.Di agnostics.TextW riterTraceListe ner, Version, Culture, PublicKeyToken"
initializeData= "MyListener.log "/>
</listeners>
</trace>
</system.diagnost ics>
</configuration>
---------------------------------------------------------------------------

As for code I followed the MSDN help for the switch, but I'm not certain of what to do for the Listener. I coded the following:

---------------------------------------------------------------------------
class Class1
{
static TraceSwitch mySwitch = new TraceSwitch("", "");
static TextWriterTrace Listener myListener = new TextWriterTrace Listener();

[STAThread]
static void Main(string[] args)
{
Console.WriteLi ne("Trace Level == {0}", mySwitch.Level) ;

Trace.WriteLine ("Hello config file based Trace");
}
}
---------------------------------------------------------------------------

When I run this program 2 rotten things happen:

1) "mySwitch.Level " returns "Off", which is not correct; it was supposed to be set to level 3 as specified in the config file.

2) I get a ConfigurationEx ception when I execute the Trace statement. The error message reads "Couldn't find type for class TextWriterTrace Listener".

Does anybody have any ideas on how to make this stuff work? MSDN help is useless in this area as everything is in piecemeal snippets with no complete working example...

Also, I get the feeling that I shouldn't have to create a listener in code, it seems to me that the listener could be created behind the scenes by the framework - yes? Do I need to have any code for the listener?

Any help would be greatly appreciated...

--Richard

Nov 16 '05 #1
2 3685
I have a partial answer to my own question:

YES the MSDN documentation is bogus. In one example the docs use a config file switch named "mySwitch" and in another example they use a config file switch named "General". The example code seems to criss cross between the two names and it never puts the correct config file switch name together with the correct name parameter as it must appear in source code. Aka the "name" parameter of the C# switch class constructor in code must match the name of the switch as it appears in the config file:

---------------------------------------------------------------------------
<switches>
<add name="mySwitch" value="3" />
</switches>
---------------------------------------------------------------------------
class Class1
{
static TraceSwitch mySwitch = new TraceSwitch("my Switch","");
}
---------------------------------------------------------------------------

"Richard" wrote:
Hi,

I'm having trouble setting up a config file based trace switch & listener. I added an application config file to my console based C# program using the "Add New Application Config File" button from solution explorer. My config file is composed of the following, which is almost a verbatum cut & paste from MSDN help:

---------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<system.diagnos tics>
<switches>
<add name="mySwitch" value="3" />
</switches>
<trace autoflush="true " indentsize="2">
<listeners>
<add name="myListene r"
type="System.Di agnostics.TextW riterTraceListe ner, Version, Culture, PublicKeyToken"
initializeData= "MyListener.log "/>
</listeners>
</trace>
</system.diagnost ics>
</configuration>
---------------------------------------------------------------------------

As for code I followed the MSDN help for the switch, but I'm not certain of what to do for the Listener. I coded the following:

---------------------------------------------------------------------------
class Class1
{
static TraceSwitch mySwitch = new TraceSwitch("", "");
static TextWriterTrace Listener myListener = new TextWriterTrace Listener();

[STAThread]
static void Main(string[] args)
{
Console.WriteLi ne("Trace Level == {0}", mySwitch.Level) ;

Trace.WriteLine ("Hello config file based Trace");
}
}
---------------------------------------------------------------------------

When I run this program 2 rotten things happen:

1) "mySwitch.Level " returns "Off", which is not correct; it was supposed to be set to level 3 as specified in the config file.

2) I get a ConfigurationEx ception when I execute the Trace statement. The error message reads "Couldn't find type for class TextWriterTrace Listener".

Does anybody have any ideas on how to make this stuff work? MSDN help is useless in this area as everything is in piecemeal snippets with no complete working example...

Also, I get the feeling that I shouldn't have to create a listener in code, it seems to me that the listener could be created behind the scenes by the framework - yes? Do I need to have any code for the listener?

Any help would be greatly appreciated...

--Richard

Nov 16 '05 #2
So do you have it working? I wrestled with this quite a while a few months
ago. As you say, the doc is questionable.

"Richard" <Ri*****@discus sions.microsoft .com> wrote in message
news:2D******** *************** ***********@mic rosoft.com...
I have a partial answer to my own question:

Nov 16 '05 #3

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

Similar topics

1
3806
by: Sean Walker | last post by:
I have installed the Microsoft Enterprise Instrumentation framework and have installed the samples. I have events successfully being logged to the Application Event Log using the Simple Instrumentation Sample Application. I cannot however get the TraceEventSink to log them, even though the Windows Trace Session Manager service is running....
8
3742
by: Geopsaros | last post by:
Hi! I have created a custom trace Listener class, called "DBTraceListener" it works fine when i add it manually in code : (eg. Trace.listeners.add(new DBTraceListener("myDBListener", TraceLevel.Verbose, getDBConnection) ) What I'm trying to achieve now is to add this listener via the MyApplication.exe.config file
3
2595
by: Joshua Coady | last post by:
Do Trace calls have any impact on performance if Trace is disabled in the config file? Josh
4
1862
by: António Pinho | last post by:
Hi, I have a big problem with an webpart/assembly. i'm trying to connect to sql server but i get the error "Request for the permission of type System.Data.SqlClient.SqlClientPermission, System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.". i've searched for it and can't find a clear answer. but one...
5
2918
by: who be dat? | last post by:
Hello all. I'm writing an application that is writing trace information that can be viewed in trace.axd. I would like to rename this and use a different name specific to my application. I know the name of this is set in machine.config. I was hoping it would be possible to change this in web.config. I got it to work, kind of. Good news is I...
9
4395
by: Joe Rattz | last post by:
I can't seem to get to trace.axd. I have turned tracing on in web.config. Here is how I currently have i configured: <trace enabled="true" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="false" />
0
3161
by: Felix | last post by:
Ok, I've had this issues since yesterday and I cannot figure out what's causing it. Basically, I have a Visual Studio 2005 Web Service. The service runs completely find on my local development environment (running WinXP, with .NET 1.1 & .NET 2.0 installed). I would normally Publish the website to another machine using the built in...
5
16537
by: MJB | last post by:
I have several dlls that have app.config files tied to them. When adding their primary output to a Setup project everything works fine, but only the app.config for the .exe gets added to the Setup project automatically. Is there any way to get the app.configs for the dlls added to the Setup without manually doing "Add File"? Thanks for the...
17
2826
by: Arpan | last post by:
When a Button is clicked in a Web Form in an ASPX page, the Form will post back to itself. Under such circumstances (i.e. when a Button is clicked), will the Page_Load sub execute first & then will the Click event function of the Button execute or will the Click event function of the Button execute first & then will the Page_Load sub execute?...
0
7693
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...
0
7605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7917
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. ...
1
7665
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...
0
7962
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...
0
3651
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...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2105
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
0
933
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...

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.