3

Is there a way to enable/disable wcf logging on the fly by modifying and reloading the app.config? I would like to be able to toggle it within my application to facilitate the design of scenarios (and the logging of the associated messages) in order to use them later in load tests.

I've read before that IIS had to reload the app pool if the web.config is modified, but my project has none, the wcf layer is completely coded and the WCF logging is enabled in the app.config, using the standard snippets available on MSDN:

<system.diagnostics >
 <sources>
   <source
       name="System.ServiceModel.MessageLogging"
       switchValue="Information, ActivityTracing" >
     <listeners>
       <add name="yourTrace"
            type="System.Diagnostics.XmlWriterTraceListener"
            initializeData="C:\Users\rfr\Desktop\Logs\YourMessageLog.svclog">
         <filter type="" />
       </add>
     </listeners>
   </source>
</sources>
<trace autoflush="true" />
</system.diagnostics>
<system.serviceModel>
 <diagnostics>
   <messageLogging
         logMessagesAtTransportLevel="false"
         logMessagesAtServiceLevel="true"
         logMalformedMessages="true"
         logEntireMessage="true"
         maxSizeOfMessageToLog="65535000" maxMessagesToLog="5000" />
 </diagnostics>
</system.serviceModel>

I guess changing the diagnostics keys to false would turn off the logging. Anyone here has insight on how to do it properly?

Keysharpener
  • 486
  • 3
  • 14
  • AFAIK the app.config is only read upon application startup. You can perhaps use a FileSystemWatcher that watches modifications to the app.config, and reloads the ServiceHost after [refreshing the configuration data](http://stackoverflow.com/a/272114/266143). – CodeCaster Oct 08 '12 at 12:45
  • What type of hosting do you use for your service? Self hosted in WPF? WAS? A Windows service? Etc? – Jeroen Oct 08 '12 at 13:08
  • They run as windows services with IIS. The services are called via a custom ChannelFactory opening and closing channels on every call. – Keysharpener Oct 08 '12 at 14:05
  • 1
    I don't know if it will help, but here is another question from someone that wanted to control WCF logging via code. His question implied some success, but not total. http://stackoverflow.com/questions/4180789/wcf-tracing-in-code-does-not-follow-messagelogging-settings – wageoghe Oct 08 '12 at 15:51
  • I finally gave up on trying to do this due to the lack of time. I now comment / uncomment this section according to my needs... – Keysharpener Dec 03 '12 at 10:18
  • I did the same thing with NLog, you can customize it to check the its config file and reload it on change – Ferran Salguero Sep 10 '14 at 13:42

0 Answers0