473,387 Members | 1,798 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,387 software developers and data experts.

Has anybody had any success inheriting from TraceSwitch class? (possible framework bug?)



I'm trying to create a tracing system for my application. I want to
create a new type of Switch that is basically TraceSwitch with an
extra attribute called "includeMethodName". So my application's config
file should look like this, for example:

<configuration>
<system.diagnostics>
<switches>
<add name="FirstSwitch" value="1" includeMethodName="1" />
<add name="SecondSwitch" value="1" includeMethodName="1" />
</switches>
</system.diagnostics>
</configuration>

The help on the Switch class is a little sparse, but from what I can
tell this should be good enough to create a simple derived switch
class:
internal class StackFrameTraceSwitch : TraceSwitch {
private const string INCLUDE_METHOD_NAME_ATTRIBUTE =
"includeMethodName";
private bool m_IncludeMethodName;

public StackFrameTraceSwitch(string displayName, string
description)
: base(displayName, description)
{
}

protected override string[] GetSupportedAttributes() {
return new string[] { INCLUDE_METHOD_NAME_ATTRIBUTE };
}

public override string ToString() {
return String.Concat
(
DisplayName,
" (",
Level.ToString(),
", ",
IncludeMethodName ? "Method Names" : "No Method
Names",
")"
);
}

public bool IncludeMethodName {
get {
foreach (DictionaryEntry entry in Attributes) {
if
(entry.Key.ToString().Equals(INCLUDE_METHOD_NAME_A TTRIBUTE,
StringComparison.OrdinalIgnoreCase)) {
string value = entry.Value.ToString();
if (value.Equals("true",
StringComparison.OrdinalIgnoreCase) ||
value.Equals("1",
StringComparison.OrdinalIgnoreCase) ||
value.Equals("yes",
StringComparison.OrdinalIgnoreCase)
)
{
m_IncludeMethodName = true;
}
}
}
return m_IncludeMethodName;
}
}
}
Problem is it won't read my custom attribute properly. If you paste
the following lines into a program and execute them

StackFrameTraceSwitch sessionSwitch = new StackFrameTraceSwitch
("FirstSwitch", "The 1st switch.");

StackFrameTraceSwitch handlerSwitch = new StackFrameTraceSwitch
("SecondSwitch", "The 2nd switch.");

you find that the includeMethodName attribute is read properly for the
first (i.e. the first one in the .config file) only. If you swap the
order of the <add ...lines in the config file then the first one is
still read properly, and the 2nd is still wrong, proving that it seems
to be dependent on the order of the lines in the file.

I can't be sure, but it looks like the Switch class's implementation
of custom attributes is not reading anything after the first switch.
You can see this in the debugger for the 2nd switch - the Attributes
property is an empty collection when it tries to iterate over it in
the IncludeMethodName property.


--
Philip Daniels
Mar 1 '07 #1
0 1090

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

Similar topics

0
by: Kevin Meiresonne | last post by:
I have developed an XML-based tracelistener which uses a booleanswitch (enable/disable), a general traceswitch (set the tracelevel) and a userspecific traceswitch (set the tracelevel for a...
3
by: thechaosengine | last post by:
Hi all, I wanted to put some common security functions into a class that inherits from the Page class and then use the new class as the basis for all my pages. Unfortunately, if I try and...
15
by: JustSomeGuy | last post by:
this doesn't want to compile.... class image : public std::list<element> { element getElement(key k) const { image::iterator iter; for (iter=begin(); iter != end(); ++iter) { element...
0
by: emy | last post by:
hello and hye everyone... can i know whether a .dll can read from traceswitch configuration file.I tried for windows application and it work well..because as far as i read, class...
2
by: nhmark64 | last post by:
Hi, When i run testapp.exe the testapp.exe.config file i have in the DEBUG directory gets deleted, and the TraceSwitch in my code never gets set. testapp.exe.config ____________________...
6
by: A.M-SG | last post by:
Hi, We are developing a SmartClient application and we are planning to expose business objects layer to SmartClient application by using ASP.NET SOAP web services.
1
by: David | last post by:
I am attempting to use "TraceSwitch " in Win Forms (Below is the code and the app.config). According to the manual, the program should read the config for the setting, but this is not occurring....
4
by: WT | last post by:
Hello, Using .NET 2 and visual studio 2005 for writting asmx web services. For asp.net web sites I used to implement trace system using TraceSwitch set in web.config. Using...
3
by: shaun roe | last post by:
Hello, I am working in a framework with certain restrictions; in particular I have a 'data' class with getter and setter methods, and a some 'filling' classes which know how to insert the data to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.