Jose,
I think that you are going about this the wrong way. Instead of
creating a timer that will remove the trace listener (which you shouldn't do
unless it is your own), why not derive a class from TraceListener? In this
class, you would have the timer with a callback. When the timer is fired,
you would create an instance of the TextWriterTraceListener and hold it
internally. Then, you would just aggregate the calls, making sure to lock
on an object so that you don't try and make a call on a null reference.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
nicholas.paldino@exisconsulting.com
"José Joye" <jose.joye@KILLTHESPAMSbluewin.ch> wrote in message
news:%23EoAnYQfDHA.2748@TK2MSFTNGP11.phx.gbl...[color=blue]
> In fact, I use from my app config file the following:
>
> <add name="BTListener"
>
> type="System.Diagnostics.TextWriterTraceListener,S ystem,[/color]
Version=1.0.5000.0,[color=blue]
> Culture=neutral, PublicKeyToken=b77a5c561934e089"
>
> initializeData="C:\temp\TestTracing.log" />
>
> <remove type="System.Diagnostics.DefaultTraceListener,Syst em,
> Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
>
>
>
> I want to allow my class clients to use this feature on the 'BTListener'
> TextWriterTraceListener. I will not be aware of the file to which it is
> attached to. This is the reason I asked the question.
>
> José
>
>
>
> "Jon Skeet" <skeet@pobox.com> wrote in message
> news:MPG.19d245343b2b36a09896cf@news.microsoft.com ...
> José Joye <jose.joye@KILLTHESPAMSbluewin.ch> wrote:[color=green]
> > You're right.
> > I will use the 'is' keyword to really see if it is a FileStream and if[/color]
> yes,[color=green]
> > I will cast it and use the 'Name' property.
> >
> > In fact, I need to know it because I have a 'TextWriterTraceListener'[/color][/color]
that[color=blue][color=green]
> > is used for logging purpose. I want to implement a timer that will[/color][/color]
remove[color=blue][color=green]
> > it from the Tracing Collection, flush it, close it and rename the file[/color]
> with[color=green]
> > a timestamp. It will then create a fresh file (with inital name) and add[/color]
> it[color=green]
> > again to the Tracing collection.
> > In this way, I want to implement a 'kind of generic' log file versioning[/color]
> in[color=green]
> > my logging class used by several applications.[/color]
>
> Why not just set the Name of the TextWriterTraceListener to be the name
> of the log file?
>
> --
> Jon Skeet - <skeet@pobox.com>
>
http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too
>
>[/color]