Custom Trace Listener & .exe.config

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Geopsaros

    Custom Trace Listener & .exe.config

    Hi!

    I have created a custom trace Listener class, called "DBTraceListene r"

    it works fine when i add it manually in code :
    (eg. Trace.listeners .add(new DBTraceListener ("myDBListener" ,
    TraceLevel.Verb ose, getDBConnection ) )

    What I'm trying to achieve now is to add this listener via the
    MyApplication.e xe.config file

    Here is my configuration file:

    <configuratio n>
    <system.diagnos tics>
    <trace autoflush="true " indentsize="4">
    <listeners>
    <remove name ="Default"/>
    <add name="myDBListe ner" type="DBTraceLi stener"/>
    </listeners>
    </trace>
    </system.diagnost ics>
    </configuration>

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

    Thanks in advance!
    G.
  • John Saunders

    #2
    Re: Custom Trace Listener &amp; .exe.config

    "Geopsaros" <Geopsaros@disc ussions.microso ft.com> wrote in message
    news:643CA5A0-2F6C-48FB-BBA8-D75CBDF6F8E8@mi crosoft.com...[color=blue]
    > Hi!
    >
    > I have created a custom trace Listener class, called "DBTraceListene r"
    >
    > it works fine when i add it manually in code :
    > (eg. Trace.listeners .add(new DBTraceListener ("myDBListener" ,
    > TraceLevel.Verb ose, getDBConnection ) )
    >
    > What I'm trying to achieve now is to add this listener via the
    > MyApplication.e xe.config file
    >
    > Here is my configuration file:
    >
    > <configuratio n>
    > <system.diagnos tics>
    > <trace autoflush="true " indentsize="4">
    > <listeners>
    > <remove name ="Default"/>
    > <add name="myDBListe ner" type="DBTraceLi stener"/>
    > </listeners>
    > </trace>
    > </system.diagnost ics>
    > </configuration>
    >
    > Unfortunately, when im executing the application the DefaultTraceLis tener
    > is
    > removed BUT my DBTraceListener is not added!!! and I dont get any
    > exceptions!
    > So what is going on?[/color]

    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 "DBTraceListene rX" and see if you get an exception.

    John Saunders


    Comment

    • Geopsaros

      #3
      Re: Custom Trace Listener &amp; .exe.config

      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 programmaticall y with
      either of those....


      "John Saunders" wrote:
      [color=blue]
      > "Geopsaros" <Geopsaros@disc ussions.microso ft.com> wrote in message
      > news:643CA5A0-2F6C-48FB-BBA8-D75CBDF6F8E8@mi crosoft.com...[color=green]
      > > Hi!
      > >
      > > I have created a custom trace Listener class, called "DBTraceListene r"
      > >
      > > it works fine when i add it manually in code :
      > > (eg. Trace.listeners .add(new DBTraceListener ("myDBListener" ,
      > > TraceLevel.Verb ose, getDBConnection ) )
      > >
      > > What I'm trying to achieve now is to add this listener via the
      > > MyApplication.e xe.config file
      > >
      > > Here is my configuration file:
      > >
      > > <configuratio n>
      > > <system.diagnos tics>
      > > <trace autoflush="true " indentsize="4">
      > > <listeners>
      > > <remove name ="Default"/>
      > > <add name="myDBListe ner" type="DBTraceLi stener"/>
      > > </listeners>
      > > </trace>
      > > </system.diagnost ics>
      > > </configuration>
      > >
      > > Unfortunately, when im executing the application the DefaultTraceLis tener
      > > is
      > > removed BUT my DBTraceListener is not added!!! and I dont get any
      > > exceptions!
      > > So what is going on?[/color]
      >
      > 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 "DBTraceListene rX" and see if you get an exception.
      >
      > John Saunders
      >
      >
      >[/color]

      Comment

      • José Joye

        #4
        Re: Custom Trace Listener &amp; .exe.config

        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.class Name)>, <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.diagnos tics>
        <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="ttcGlobal Switch" value="4" />
        </switches>
        <trace>
        <listeners>
        <remove name="Default" />
        <add name="ttcTextLi stener"
        type="Company.B ase.ttcTextTrac eListener,Compa ny.Base"/>
        <add name="ttcEventL ogListener"
        type="Company.B ase.ttcEventLog TraceListener,C ompany.Base"/>
        <add name="ttcMailLi stener"
        type="Company.B ase.ttcMailTrac eListener,Compa ny.Base"/>
        </listeners>
        </trace>
        </system.diagnost ics>

        "Geopsaros" <Geopsaros@disc ussions.microso ft.com> a écrit dans le message de
        news:643CA5A0-2F6C-48FB-BBA8-D75CBDF6F8E8@mi crosoft.com...[color=blue]
        > Hi!
        >
        > I have created a custom trace Listener class, called "DBTraceListene r"
        >
        > it works fine when i add it manually in code :
        > (eg. Trace.listeners .add(new DBTraceListener ("myDBListener" ,
        > TraceLevel.Verb ose, getDBConnection ) )
        >
        > What I'm trying to achieve now is to add this listener via the
        > MyApplication.e xe.config file
        >
        > Here is my configuration file:
        >
        > <configuratio n>
        > <system.diagnos tics>
        > <trace autoflush="true " indentsize="4">
        > <listeners>
        > <remove name ="Default"/>
        > <add name="myDBListe ner" type="DBTraceLi stener"/>
        > </listeners>
        > </trace>
        > </system.diagnost ics>
        > </configuration>
        >
        > Unfortunately, when im executing the application the DefaultTraceLis tener[/color]
        is[color=blue]
        > removed BUT my DBTraceListener is not added!!! and I dont get any[/color]
        exceptions![color=blue]
        > So what is going on?
        >
        > Thanks in advance!
        > G.[/color]


        Comment

        • Geopsaros

          #5
          Re: Custom Trace Listener &amp; .exe.config

          I'll give some more details because i still cant make it work :(

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

          e.g Class DBFacade
          ......
          Class DBTraceListener
          ......
          End class 'DBTraceListene r
          End class 'DBFacade


          My Solution's starting project is called "ForeignOfficeV 2" and its a Windows
          Application.

          There arent any namespaces declared! Hence, the listener add line should be
          : <add name="DBListene rFromConfigFile "
          type="DBAcces.D BFacade.DBTrace Listener,DBAcce s"/>


          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:
          [color=blue]
          > 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.class Name)>, <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.diagnos tics>
          > <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="ttcGlobal Switch" value="4" />
          > </switches>
          > <trace>
          > <listeners>
          > <remove name="Default" />
          > <add name="ttcTextLi stener"
          > type="Company.B ase.ttcTextTrac eListener,Compa ny.Base"/>
          > <add name="ttcEventL ogListener"
          > type="Company.B ase.ttcEventLog TraceListener,C ompany.Base"/>
          > <add name="ttcMailLi stener"
          > type="Company.B ase.ttcMailTrac eListener,Compa ny.Base"/>
          > </listeners>
          > </trace>
          > </system.diagnost ics>
          >
          > "Geopsaros" <Geopsaros@disc ussions.microso ft.com> a écrit dans le message de
          > news:643CA5A0-2F6C-48FB-BBA8-D75CBDF6F8E8@mi crosoft.com...[color=green]
          > > Hi!
          > >
          > > I have created a custom trace Listener class, called "DBTraceListene r"
          > >
          > > it works fine when i add it manually in code :
          > > (eg. Trace.listeners .add(new DBTraceListener ("myDBListener" ,
          > > TraceLevel.Verb ose, getDBConnection ) )
          > >
          > > What I'm trying to achieve now is to add this listener via the
          > > MyApplication.e xe.config file
          > >
          > > Here is my configuration file:
          > >
          > > <configuratio n>
          > > <system.diagnos tics>
          > > <trace autoflush="true " indentsize="4">
          > > <listeners>
          > > <remove name ="Default"/>
          > > <add name="myDBListe ner" type="DBTraceLi stener"/>
          > > </listeners>
          > > </trace>
          > > </system.diagnost ics>
          > > </configuration>
          > >
          > > Unfortunately, when im executing the application the DefaultTraceLis tener[/color]
          > is[color=green]
          > > removed BUT my DBTraceListener is not added!!! and I dont get any[/color]
          > exceptions![color=green]
          > > So what is going on?
          > >
          > > Thanks in advance!
          > > G.[/color]
          >
          >
          >[/color]

          Comment

          • John Saunders

            #6
            Re: Custom Trace Listener &amp; .exe.config

            "Geopsaros" <Geopsaros@disc ussions.microso ft.com> wrote in message
            news:5F3F3D84-DB1E-4CD4-AB0C-DE8BEB64ABCD@mi crosoft.com...[color=blue]
            > I'll give some more details because i still cant make it work :(
            >
            > My custom tracelistener is a class called "DBTraceListene r"
            > This class is inside a class called "DBFacade", which is declared
            > in a project called "DBAcces"[/color]

            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.Ass emblyQualifiedN ame.

            John Saunders


            Comment

            • Geopsaros

              #7
              Re: Custom Trace Listener &amp; .exe.config

              I moved the "DBTraceListene r" class in a separate file in the "DBAcces"
              project and YES it finally Worked!!!!

              the add listener line is now as follows:
              type="DBAcces.D BTraceListener, 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:
              [color=blue]
              > "Geopsaros" <Geopsaros@disc ussions.microso ft.com> wrote in message
              > news:5F3F3D84-DB1E-4CD4-AB0C-DE8BEB64ABCD@mi crosoft.com...[color=green]
              > > I'll give some more details because i still cant make it work :(
              > >
              > > My custom tracelistener is a class called "DBTraceListene r"
              > > This class is inside a class called "DBFacade", which is declared
              > > in a project called "DBAcces"[/color]
              >
              > 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.Ass emblyQualifiedN ame.
              >
              > John Saunders
              >
              >
              >[/color]

              Comment

              • José Joye

                #8
                Re: Custom Trace Listener &amp; .exe.config

                If you have not defined any namespace within the DBAccess then you should
                (at least I guess...) have the following:
                [color=blue]
                > : <add name="DBListene rFromConfigFile "
                > type="DBFacade. DBTraceListener ,DBAcces"/>[/color]

                I assume that your DBTraceListener class derives from
                System.Diagnost ics.TraceListen er 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" <Geopsaros@disc ussions.microso ft.com> wrote in message
                news:5F3F3D84-DB1E-4CD4-AB0C-DE8BEB64ABCD@mi crosoft.com...[color=blue]
                > I'll give some more details because i still cant make it work :(
                >
                > My custom tracelistener is a class called "DBTraceListene r"
                > This class is inside a class called "DBFacade", which is declared
                > in a project called "DBAcces"
                >
                > e.g Class DBFacade
                > ......
                > Class DBTraceListener
                > ......
                > End class 'DBTraceListene r
                > End class 'DBFacade
                >
                >
                > My Solution's starting project is called "ForeignOfficeV 2" and its a[/color]
                Windows[color=blue]
                > Application.
                >
                > There arent any namespaces declared! Hence, the listener add line should[/color]
                be[color=blue]
                > : <add name="DBListene rFromConfigFile "
                > type="DBAcces.D BFacade.DBTrace Listener,DBAcce s"/>
                >
                >
                > 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:
                >[color=green]
                > > 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.class Name)>, <dll name that holds[/color][/color]
                the[color=blue][color=green]
                > > class>"
                > >
                > > By the way, the default CTOR gets called when pluggin from the config[/color][/color]
                file.[color=blue][color=green]
                > >
                > > Hope this help,
                > > José
                > >
                > >
                > > Snippet:
                > > --------
                > > <system.diagnos tics>
                > > <switches>
                > > <!-- Global switch used by ttc programs. This is the master[/color][/color]
                switch.[color=blue][color=green]
                > > Any severity values
                > > above this level will be blocked and not passed to the[/color][/color]
                registered[color=blue][color=green]
                > > ttc listeners.
                > > Valid values are: 0:none, 1:error, 2:warning, 3: info,
                > > -->
                > > <add name="ttcGlobal Switch" value="4" />
                > > </switches>
                > > <trace>
                > > <listeners>
                > > <remove name="Default" />
                > > <add name="ttcTextLi stener"
                > > type="Company.B ase.ttcTextTrac eListener,Compa ny.Base"/>
                > > <add name="ttcEventL ogListener"
                > > type="Company.B ase.ttcEventLog TraceListener,C ompany.Base"/>
                > > <add name="ttcMailLi stener"
                > > type="Company.B ase.ttcMailTrac eListener,Compa ny.Base"/>
                > > </listeners>
                > > </trace>
                > > </system.diagnost ics>
                > >
                > > "Geopsaros" <Geopsaros@disc ussions.microso ft.com> a écrit dans le[/color][/color]
                message de[color=blue][color=green]
                > > news:643CA5A0-2F6C-48FB-BBA8-D75CBDF6F8E8@mi crosoft.com...[color=darkred]
                > > > Hi!
                > > >
                > > > I have created a custom trace Listener class, called "DBTraceListene r"
                > > >
                > > > it works fine when i add it manually in code :
                > > > (eg. Trace.listeners .add(new DBTraceListener ("myDBListener" ,
                > > > TraceLevel.Verb ose, getDBConnection ) )
                > > >
                > > > What I'm trying to achieve now is to add this listener via the
                > > > MyApplication.e xe.config file
                > > >
                > > > Here is my configuration file:
                > > >
                > > > <configuratio n>
                > > > <system.diagnos tics>
                > > > <trace autoflush="true " indentsize="4">
                > > > <listeners>
                > > > <remove name ="Default"/>
                > > > <add name="myDBListe ner" type="DBTraceLi stener"/>
                > > > </listeners>
                > > > </trace>
                > > > </system.diagnost ics>
                > > > </configuration>
                > > >
                > > > Unfortunately, when im executing the application the[/color][/color][/color]
                DefaultTraceLis tener[color=blue][color=green]
                > > is[color=darkred]
                > > > removed BUT my DBTraceListener is not added!!! and I dont get any[/color]
                > > exceptions![color=darkred]
                > > > So what is going on?
                > > >
                > > > Thanks in advance!
                > > > G.[/color]
                > >
                > >
                > >[/color][/color]


                Comment

                • John Saunders

                  #9
                  Re: Custom Trace Listener &amp; .exe.config

                  "Geopsaros" <Geopsaros@disc ussions.microso ft.com> wrote in message
                  news:6A7C32DF-7BBC-47D1-B4D4-BC804B6CE892@mi crosoft.com...[color=blue]
                  >I moved the "DBTraceListene r" class in a separate file in the "DBAcces"
                  > project and YES it finally Worked!!!!
                  >
                  > the add listener line is now as follows:
                  > type="DBAcces.D BTraceListener, 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?[/color]
                  [color=blue][color=green]
                  >> Afterwards, take a look at System.Type.Ass emblyQualifiedN ame.[/color][/color]

                  John

                  [color=blue]
                  > "John Saunders" wrote:
                  >[color=green]
                  >> "Geopsaros" <Geopsaros@disc ussions.microso ft.com> wrote in message
                  >> news:5F3F3D84-DB1E-4CD4-AB0C-DE8BEB64ABCD@mi crosoft.com...[color=darkred]
                  >> > I'll give some more details because i still cant make it work :(
                  >> >
                  >> > My custom tracelistener is a class called "DBTraceListene r"
                  >> > This class is inside a class called "DBFacade", which is declared
                  >> > in a project called "DBAcces"[/color]
                  >>
                  >> 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.Ass emblyQualifiedN ame.
                  >>
                  >> John Saunders
                  >>
                  >>
                  >>[/color][/color]


                  Comment

                  Working...