Custom Trace Listener & .exe.config

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
Geopsaros said:
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
 
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....
 
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.Base"/>
<add name="ttcEventLogListener"
type="Company.Base.ttcEventLogTraceListener,Company.Base"/>
<add name="ttcMailListener"
type="Company.Base.ttcMailTraceListener,Company.Base"/>
</listeners>
</trace>
</system.diagnostics>
 
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!
 
Geopsaros said:
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
 
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?
 
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 said:
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
 
Back
Top