title: Error when handling NServiceBus Subscription messages
body: <p>After adding logging (using log4net) to my application, it no longer handles subscription messages correctly and puts them on to the error queue. Below, some namespace names have been changed to protect the innocent.</p>
  
  <p><strong>app.config</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
  &lt;configSections&gt;
      &lt;section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" /&gt;
      &lt;section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" /&gt;
      &lt;section name="MsmqSubscriptionStorageConfig" type="NServiceBus.Config.MsmqSubscriptionStorageConfig, NServiceBus.Core" /&gt;
      &lt;section name="Logging" type="NServiceBus.Config.Logging, NServiceBus.Core" /&gt;
      &lt;section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /&gt;
  &lt;/configSections&gt;
  
  &lt;Logging Threshold="INFO" /&gt;
  
  &lt;log4net&gt;
      &lt;appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender"&gt;
          &lt;layout type="log4net.Layout.PatternLayout"&gt;
              &lt;param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &amp;lt;%X{auth}&amp;gt; - %m%n"/&gt;
          &lt;/layout&gt;
      &lt;/appender&gt;
      &lt;appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" &gt;
          &lt;layout type="log4net.Layout.PatternLayout"&gt;
              &lt;param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &amp;lt;%X{auth}&amp;gt; - %m%n"/&gt;
          &lt;/layout&gt;
      &lt;/appender&gt;
      &lt;appender name="TraceAppender" type="log4net.Appender.TraceAppender"&gt;
          &lt;layout type="log4net.Layout.PatternLayout"&gt;
              &lt;param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &amp;lt;%X{auth}&amp;gt; - %m%n"/&gt;
          &lt;/layout&gt;
      &lt;/appender&gt;
      &lt;appender name="FileAppender" type="log4net.Appender.FileAppender"&gt;
          &lt;file value="logfile.txt" /&gt;
          &lt;appendToFile value="true" /&gt;
          &lt;layout type="log4net.Layout.PatternLayout"&gt;
              &lt;conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" /&gt;
          &lt;/layout&gt;
      &lt;/appender&gt;
      &lt;root&gt;
          &lt;level value="INFO"/&gt;
          &lt;appender-ref ref="ConsoleAppender"/&gt;
          &lt;appender-ref ref="FileAppender"/&gt;
      &lt;/root&gt;
  &lt;/log4net&gt;
  
  &lt;MsmqTransportConfig
    InputQueue="BankRequestDispatcherInputQueue_DEV2"
    ErrorQueue="error"
    NumberOfWorkerThreads="1"
    MaxRetries="5"
  /&gt;
  
  &lt;UnicastBusConfig ForwardReceivedMessagesTo="auditqueue"&gt;
      &lt;MessageEndpointMappings&gt;
          &lt;add Messages="&lt;assembly&gt;.BankRequestBatchClosed,&lt;assembly&gt;" Endpoint="ScheduledBatchAgentInputQueue_DEV2" /&gt;
      &lt;/MessageEndpointMappings&gt;
  &lt;/UnicastBusConfig&gt;
  
  &lt;MsmqSubscriptionStorageConfig Queue="BRDispatcher_DEV2_subscriptions" /&gt;
  
  &lt;!-- Neccessary for Fluent/NHibernate/SQLLite dlls --&gt;
  &lt;startup useLegacyV2RuntimeActivationPolicy="true"&gt;
      &lt;supportedRuntime version="v4.0"  sku=".NETFramework,Version=v4.0"/&gt;
  &lt;/startup&gt;
  &lt;appSettings&gt;
      &lt;add key="TempRequestFileLocation" value="c:\temp\"/&gt;
      &lt;add key="KeepRequestFiles" value="true"/&gt;
      &lt;add key="Environment" value="TEST"/&gt;
  &lt;/appSettings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I've also changed the <strong>Endpoint config</strong> to this:</p>
  
  <pre><code>namespace myNamespace.BRDispatcher
  {
      /// &lt;summary&gt;
      /// Interface tells NServiceBus which roles to setup for this class. 
      /// &lt;/summary&gt; 
      public class BRDEndpointConfig : IConfigureThisEndpoint, IWantCustomInitialization
      {
          #region Class References -1-
          /// &lt;summary&gt;
          /// Reference to Logger object.
          /// &lt;/summary&gt;
          private static readonly ILog Logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
          #endregion
      public void Init()
      {
          NServiceBus.SetLoggingLibrary.Log4Net(log4net.Config.XmlConfigurator.Configure);
  
          Logger.Info("BankRequestDispatcher - Init()");
  
          NServiceBus.Configure.With()
              //.Log4Net()
            .DefaultBuilder()
            .XmlSerializer()
            .MsmqSubscriptionStorage()
            .MsmqTransport()
               .IsTransactional(true)
               .PurgeOnStartup(false)
            .UnicastBus()
               .ImpersonateSender(false)
               .LoadMessageHandlers()
            .CreateBus()
            .Start();
  
          Logger.Info("BankRequestDispatcher - Init() Complete");
      }
  }
  }
  </code></pre>
  
  <p>When it fires up, any subscription message received gets dumped onto the error queue and I see this in the log:</p>
  
  <pre><code>2012-02-22 17:02:48,013 [Worker.8] ERROR NServiceBus.Unicast.Transport.Msmq.MsmqTransport [(null)] - Message has failed the maximum number of times allowed, ID=94b95c71-896f-4991-b3ba-9d2068a68c63\81504.
  </code></pre>