WCF logging: Why isn't Close being called for TraceListener?
I'm trying to log messages to my WCF service at transport level. I've followed some instructions I found on the net successfully, but now I want to implement my own trace listener that supports our in-house logging solution.
I've implemented a trace listener and I configure it using the app.config
of my windows service hosting the WCF service. The following is the XML I use to configure the logging.
<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="messages" type="my.namespace.AdvancedLogTraceListener, Tools.Logging, Version=2.0.3.1, Culture=neutral" initializeData="C:\Logs" />
</listeners>
</source>
</sources>
</system.diagnostics>
...
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="false" logMessagesAtServiceLevel="false" logMessagesAtTransportLevel="true">
</messageLogging>
</diagnostics>
All of this works pretty well. However: Our in-house logging solution is used like a class. This class starts a background thread to perform actions like log-cleaning, do the actual logging asynchronously, etc. 开发者_开发百科The class requires a method named Close
to be called when closing the application, which stops the internal processing and exits the thread.
The TraceListener
class, which my TraceListener
inherits from, implements a Close
method. I've overridden this method as follows:
public override void Close()
{
base.Close();
this.logFile.Close();
}
Only that it doesn't work. The Close
method of the TraceListener
does not seem to get called. What should I do to ensure that I can call my Close
method when the application hosting the WCF service is closed?
Nevers mind, I found another solution implementing message inspectors.
精彩评论