How to rotate WCF log when maxMessagesToLog is reached?

Jun 13 2019 2:50 AM
I have a WCF service and want to enable logging. As described in Microsoft's documentation [Configuring Message Logging](, I put in the Web.config the following:
  1. <system.diagnostics>    
  2.   <sources>    
  3.     <source name="System.ServiceModel.MessageLogging">    
  4.       <listeners>    
  5.          <add name="messages"    
  6.               type="System.Diagnostics.XmlWriterTraceListener"    
  7.               initializeData="c:\logs\messages.svclog" />    
  8.         </listeners>    
  9.     </source>    
  10.   </sources>    
  11. </system.diagnostics>    
  13. <system.serviceModel>    
  14.   <diagnostics>    
  15.     <messageLogging     
  16.          logEntireMessage="true"     
  17.          logMalformedMessages="false"    
  18.          logMessagesAtServiceLevel="true"     
  19.          logMessagesAtTransportLevel="false"    
  20.          maxMessagesToLog="3000"    
  21.          maxSizeOfMessageToLog="2000"/>    
  22.   </diagnostics>    
  23. </system.serviceModel>    
How can I rotate the log, for example write to messages1.svclog, then messages2.svclog, etc. when the number of messages in the last log has reached maxMessagesToLog=3000?
I read the article [A Rolling XmlWriterTraceListener](, but this rotates the log file when a certain file size has been reached. However, when the number of messages reaches maxMessagesToLog, WCF will stop logging.

Brought to you by: