469,646 Members | 1,471 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,646 developers. It's quick & easy.

Custom Trace Listener & .exe.config

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

Here is my configuration file:

<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<remove name ="Default"/>
<add name="myDBListener" type="DBTraceListener"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>

Unfortunately, when im executing the application the DefaultTraceListener is
removed BUT my DBTraceListener is not added!!! and I dont get any exceptions!
So what is going on?

Thanks in advance!
G.
Jul 21 '05 #1
8 3486
"Geopsaros" <Ge*******@discussions.microsoft.com> wrote in message
news:64**********************************@microsof t.com...
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

Here is my configuration file:

<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<remove name ="Default"/>
<add name="myDBListener" type="DBTraceListener"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>

Unfortunately, when im executing the application the DefaultTraceListener
is
removed BUT my DBTraceListener is not added!!! and I dont get any
exceptions!
So what is going on?


From the above, it looks like your listener requires three parameters in its
constructor. How would those parameters be passed to it by the config file?

I'm surprised you don't get an exception, though. Try this experiment:
Change the "type" to "DBTraceListenerX" and see if you get an exception.

John Saunders
Jul 21 '05 #2
John, i have tried it! No exceptions, no errors ...nothing
I have also tried type="" and No type attribute at all!

As far as the constructor is concerced, There are 2 constructors,
one without parameters and one with 3 parameters.

The DBTraceListener works without problems when added programmatically with
either of those....
"John Saunders" wrote:
"Geopsaros" <Ge*******@discussions.microsoft.com> wrote in message
news:64**********************************@microsof t.com...
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

Here is my configuration file:

<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<remove name ="Default"/>
<add name="myDBListener" type="DBTraceListener"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>

Unfortunately, when im executing the application the DefaultTraceListener
is
removed BUT my DBTraceListener is not added!!! and I dont get any
exceptions!
So what is going on?


From the above, it looks like your listener requires three parameters in its
constructor. How would those parameters be passed to it by the config file?

I'm surprised you don't get an exception, though. Try this experiment:
Change the "type" to "DBTraceListenerX" and see if you get an exception.

John Saunders

Jul 21 '05 #3
Below is an extract of what I used:

In fact, you have to fully identify your listener in the type attribute.

type="<fully qualified class (assembly.className)>, <dll name that holds the
class>"

By the way, the default CTOR gets called when pluggin from the config file.

Hope this help,
José
Snippet:
--------
<system.diagnostics>
<switches>
<!-- Global switch used by ttc programs. This is the master switch.
Any severity values
above this level will be blocked and not passed to the registered
ttc listeners.
Valid values are: 0:none, 1:error, 2:warning, 3: info,
-->
<add name="ttcGlobalSwitch" value="4" />
</switches>
<trace>
<listeners>
<remove name="Default" />
<add name="ttcTextListener"
type="Company.Base.ttcTextTraceListener,Company.Ba se"/>
<add name="ttcEventLogListener"
type="Company.Base.ttcEventLogTraceListener,Compan y.Base"/>
<add name="ttcMailListener"
type="Company.Base.ttcMailTraceListener,Company.Ba se"/>
</listeners>
</trace>
</system.diagnostics>

"Geopsaros" <Ge*******@discussions.microsoft.com> a écrit dans le message de
news:64**********************************@microsof t.com...
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

Here is my configuration file:

<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<remove name ="Default"/>
<add name="myDBListener" type="DBTraceListener"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>

Unfortunately, when im executing the application the DefaultTraceListener is removed BUT my DBTraceListener is not added!!! and I dont get any exceptions! So what is going on?

Thanks in advance!
G.

Jul 21 '05 #4
I'll give some more details because i still cant make it work :(

My custom tracelistener is a class called "DBTraceListener"
This class is inside a class called "DBFacade", which is declared
in a project called "DBAcces"

e.g Class DBFacade
......
Class DBTraceListener
......
End class 'DBTraceListener
End class 'DBFacade
My Solution's starting project is called "ForeignOfficeV2" and its a Windows
Application.

There arent any namespaces declared! Hence, the listener add line should be
: <add name="DBListenerFromConfigFile"
type="DBAcces.DBFacade.DBTraceListener,DBAcces"/>
Am I right? In case I am not, i'm also wondering why I dont get any
exceptions or error messages?

Any help is really appreciated!
"José Joye" wrote:
Below is an extract of what I used:

In fact, you have to fully identify your listener in the type attribute.

type="<fully qualified class (assembly.className)>, <dll name that holds the
class>"

By the way, the default CTOR gets called when pluggin from the config file.

Hope this help,
José
Snippet:
--------
<system.diagnostics>
<switches>
<!-- Global switch used by ttc programs. This is the master switch.
Any severity values
above this level will be blocked and not passed to the registered
ttc listeners.
Valid values are: 0:none, 1:error, 2:warning, 3: info,
-->
<add name="ttcGlobalSwitch" value="4" />
</switches>
<trace>
<listeners>
<remove name="Default" />
<add name="ttcTextListener"
type="Company.Base.ttcTextTraceListener,Company.Ba se"/>
<add name="ttcEventLogListener"
type="Company.Base.ttcEventLogTraceListener,Compan y.Base"/>
<add name="ttcMailListener"
type="Company.Base.ttcMailTraceListener,Company.Ba se"/>
</listeners>
</trace>
</system.diagnostics>

"Geopsaros" <Ge*******@discussions.microsoft.com> a écrit dans le message de
news:64**********************************@microsof t.com...
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

Here is my configuration file:

<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<remove name ="Default"/>
<add name="myDBListener" type="DBTraceListener"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>

Unfortunately, when im executing the application the DefaultTraceListener

is
removed BUT my DBTraceListener is not added!!! and I dont get any

exceptions!
So what is going on?

Thanks in advance!
G.


Jul 21 '05 #5
"Geopsaros" <Ge*******@discussions.microsoft.com> wrote in message
news:5F**********************************@microsof t.com...
I'll give some more details because i still cant make it work :(

My custom tracelistener is a class called "DBTraceListener"
This class is inside a class called "DBFacade", which is declared
in a project called "DBAcces"


What happens when you "don't do that"? Pull the listener out to top level
and see what happens.

Afterwards, take a look at System.Type.AssemblyQualifiedName.

John Saunders
Jul 21 '05 #6
I moved the "DBTraceListener" class in a separate file in the "DBAcces"
project and YES it finally Worked!!!!

the add listener line is now as follows:
type="DBAcces.DBTraceListener,DBAcces"/>

thanks a lot John!

I hope someone can answer why a listener cant be added
when its class is declared inside another class, or how this can be done?

"John Saunders" wrote:
"Geopsaros" <Ge*******@discussions.microsoft.com> wrote in message
news:5F**********************************@microsof t.com...
I'll give some more details because i still cant make it work :(

My custom tracelistener is a class called "DBTraceListener"
This class is inside a class called "DBFacade", which is declared
in a project called "DBAcces"


What happens when you "don't do that"? Pull the listener out to top level
and see what happens.

Afterwards, take a look at System.Type.AssemblyQualifiedName.

John Saunders

Jul 21 '05 #7
If you have not defined any namespace within the DBAccess then you should
(at least I guess...) have the following:
: <add name="DBListenerFromConfigFile"
type="DBFacade.DBTraceListener,DBAcces"/>
I assume that your DBTraceListener class derives from
System.Diagnostics.TraceListener and your DBAccess project generates a
DBAccess.dll file which is located in the same directory as your
xyz.exe.config file.

Hope this help,
-José

"Geopsaros" <Ge*******@discussions.microsoft.com> wrote in message
news:5F**********************************@microsof t.com... I'll give some more details because i still cant make it work :(

My custom tracelistener is a class called "DBTraceListener"
This class is inside a class called "DBFacade", which is declared
in a project called "DBAcces"

e.g Class DBFacade
......
Class DBTraceListener
......
End class 'DBTraceListener
End class 'DBFacade
My Solution's starting project is called "ForeignOfficeV2" and its a Windows Application.

There arent any namespaces declared! Hence, the listener add line should be : <add name="DBListenerFromConfigFile"
type="DBAcces.DBFacade.DBTraceListener,DBAcces"/>
Am I right? In case I am not, i'm also wondering why I dont get any
exceptions or error messages?

Any help is really appreciated!
"José Joye" wrote:
Below is an extract of what I used:

In fact, you have to fully identify your listener in the type attribute.

type="<fully qualified class (assembly.className)>, <dll name that holds the class>"

By the way, the default CTOR gets called when pluggin from the config file.
Hope this help,
José
Snippet:
--------
<system.diagnostics>
<switches>
<!-- Global switch used by ttc programs. This is the master switch. Any severity values
above this level will be blocked and not passed to the registered ttc listeners.
Valid values are: 0:none, 1:error, 2:warning, 3: info,
-->
<add name="ttcGlobalSwitch" value="4" />
</switches>
<trace>
<listeners>
<remove name="Default" />
<add name="ttcTextListener"
type="Company.Base.ttcTextTraceListener,Company.Ba se"/>
<add name="ttcEventLogListener"
type="Company.Base.ttcEventLogTraceListener,Compan y.Base"/>
<add name="ttcMailListener"
type="Company.Base.ttcMailTraceListener,Company.Ba se"/>
</listeners>
</trace>
</system.diagnostics>

"Geopsaros" <Ge*******@discussions.microsoft.com> a écrit dans le message de news:64**********************************@microsof t.com...
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

Here is my configuration file:

<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<remove name ="Default"/>
<add name="myDBListener" type="DBTraceListener"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>

Unfortunately, when im executing the application the
DefaultTraceListener is
removed BUT my DBTraceListener is not added!!! and I dont get any

exceptions!
So what is going on?

Thanks in advance!
G.


Jul 21 '05 #8
"Geopsaros" <Ge*******@discussions.microsoft.com> wrote in message
news:6A**********************************@microsof t.com...
I moved the "DBTraceListener" class in a separate file in the "DBAcces"
project and YES it finally Worked!!!!

the add listener line is now as follows:
type="DBAcces.DBTraceListener,DBAcces"/>

thanks a lot John!

I hope someone can answer why a listener cant be added
when its class is declared inside another class, or how this can be done?
Afterwards, take a look at System.Type.AssemblyQualifiedName.


John

"John Saunders" wrote:
"Geopsaros" <Ge*******@discussions.microsoft.com> wrote in message
news:5F**********************************@microsof t.com...
> I'll give some more details because i still cant make it work :(
>
> My custom tracelistener is a class called "DBTraceListener"
> This class is inside a class called "DBFacade", which is declared
> in a project called "DBAcces"


What happens when you "don't do that"? Pull the listener out to top level
and see what happens.

Afterwards, take a look at System.Type.AssemblyQualifiedName.

John Saunders

Jul 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Richard | last post: by
3 posts views Thread by Schorschi | last post: by
2 posts views Thread by Jason L James | last post: by
8 posts views Thread by Geopsaros | last post: by
1 post views Thread by Tris | last post: by
reply views Thread by boldtbanan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.