TraceListener.Close not called when added through config file...
-
I have written a trace listener that has at least one worker thread to process an internal buffer. When the Close method is called explicitly from within the hosting application, everthing is fine and dandy, but if i add the TraceListener from the system.diagnostics section of the config file, the Close method doesn't ever get called. Does anyone have any idea when that method gets called when added through the config file?
-
I have written a trace listener that has at least one worker thread to process an internal buffer. When the Close method is called explicitly from within the hosting application, everthing is fine and dandy, but if i add the TraceListener from the system.diagnostics section of the config file, the Close method doesn't ever get called. Does anyone have any idea when that method gets called when added through the config file?
The correct solution is probably to implemente the IDisposable interface on your trace listener. When that object is disposed, you can call the Close method yourself. John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek. -
The correct solution is probably to implemente the IDisposable interface on your trace listener. When that object is disposed, you can call the Close method yourself. John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.Hmm - turns out a i forgot a vital piece of infornmation. The hosting application hangs when this problem occurs. I implement the Dispose( bool ) method for just this issue, but it never gets to a point where that would be feasible. It appears, at first glance, that the framework is looking for all the threads owned by the hosting app to finish as its trigger for releasing the dynamic config listeners. It becomes a catch-22, it won't call Close until all threads complete, but I can't know to complete my thread without Close being called. :P Ugh - I really don't want to require explicit addition and closure of this tracelistener, even though it would be understandable concidering the purpose and goal of this specific listener implementation.
-
Hmm - turns out a i forgot a vital piece of infornmation. The hosting application hangs when this problem occurs. I implement the Dispose( bool ) method for just this issue, but it never gets to a point where that would be feasible. It appears, at first glance, that the framework is looking for all the threads owned by the hosting app to finish as its trigger for releasing the dynamic config listeners. It becomes a catch-22, it won't call Close until all threads complete, but I can't know to complete my thread without Close being called. :P Ugh - I really don't want to require explicit addition and closure of this tracelistener, even though it would be understandable concidering the purpose and goal of this specific listener implementation.
Cromwell wrote: I implement the Dispose( bool ) That looks somewhat suspicious to me. The IDisposable interface only has Dispose() as a member. If you are not implementing the actual members of IDisposable, give that a try first. John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek. -
Cromwell wrote: I implement the Dispose( bool ) That looks somewhat suspicious to me. The IDisposable interface only has Dispose() as a member. If you are not implementing the actual members of IDisposable, give that a try first. John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.True, i haven't implementing the raw Dispose() yet. I'll give it a try, but i'm not holding out hope. :) Dispose( bool ) is the de-facto method for classes that have finalizers and is implemented by a number of classes, including the TraceListener base class.
-
Cromwell wrote: I implement the Dispose( bool ) That looks somewhat suspicious to me. The IDisposable interface only has Dispose() as a member. If you are not implementing the actual members of IDisposable, give that a try first. John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.yup - can't override the TraceListener.Dispose method. You have to override the Dispose( bool ) method which i've done and had no luck with. Stupid Dispose!
-
Cromwell wrote: I implement the Dispose( bool ) That looks somewhat suspicious to me. The IDisposable interface only has Dispose() as a member. If you are not implementing the actual members of IDisposable, give that a try first. John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.OK - So I figured out a solution, but I have to determine the impact. The worker thread IsBackground property had been set to false, mainly to increase performance. (This is supposed to be part of a high-performance, low impact auditing framework we are writing) I'm going to make the assumption that the Trace framework, waits for all non-background threads to complete before calling close. Thanks for the help...
-
OK - So I figured out a solution, but I have to determine the impact. The worker thread IsBackground property had been set to false, mainly to increase performance. (This is supposed to be part of a high-performance, low impact auditing framework we are writing) I'm going to make the assumption that the Trace framework, waits for all non-background threads to complete before calling close. Thanks for the help...
Glad you found a solution, but I still question the Dispose use. Have you actually put a " : IDisposable" at the end of your class definition? If not, you can do that and then supply at minumum an IDisposable.Dispose() implementation. This will be separate from any dependency upon being able to inherit from TraceListener, but you may need to call the base.Dispose() method to properly clean things up. John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.