title: Upgrading Application from Enterprise Library 5 to 6
body: <p>I am upgrading an existing application from 5 to 6.  My application is a .NET web application.  I rely on Enterprise library to log any errors to the database (sql server).  </p>
  
  <p>My application also uses a custom database listener and a custom Logging Exception Handler (both in the form of separate .net projects within my solution). </p>
  
  <p>So, I have 6 installed, and have added the following code to Application_Start-</p>
  
  <pre><code>             IConfigurationSource config = ConfigurationSourceFactory.Create();
          ExceptionPolicyFactory factory = new ExceptionPolicyFactory(config);
          Logger.SetLogWriter(new LogWriterFactory().Create());
  
          ExceptionManager exceptionManager = factory.CreateManager();
  </code></pre>
  
  <p>I get a System.NotImplementedException when it hits the Logger.SetLogWriter(new LogWriterFactory().Create()); line of code.  </p>
  
  <p>EDIT:  More specific error details</p>
  
  <pre><code> System.NotImplementedException was unhandled by user code
   HResult=-2147467263
   Message=Must be implemented by subclasses.
   Source=Microsoft.Practices.EnterpriseLibrary.Logging
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p>Here is my web.config-</p>
  
  <pre><code>   &lt;configSections&gt;
  &lt;section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" requirePermission="true" /&gt;
  &lt;section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" /&gt;
  &lt;section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" /&gt;
  
  
   &lt;/configSections&gt;
  &lt;loggingConfiguration name="" tracingEnabled="true" defaultCategory="General"&gt;
  &lt;listeners&gt;
    &lt;add name="Database Trace Listener" type="ExtendedPropertyDatabaseListener.ExtendedFormattedDatabaseTraceListener, ExtendedPropertyDatabaseListener" listenerDataType="ExtendedPropertyDatabaseListener.ExtendedFormattedDatabaseTraceListenerData, ExtendedPropertyDatabaseListener" databaseInstanceName="ablmprod" writeLogStoredProcName="Logging.WriteLog" addCategoryStoredProcName="Logging.AddCategory" formatter="Text Formatter" /&gt;
    &lt;add name="Event Log Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" source="Enterprise Library Logging" formatter="Text Formatter" /&gt;
  &lt;/listeners&gt;
  &lt;formatters&gt;
    &lt;add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" template="Timestamp: {timestamp}{newline}&amp;#xA;Message: {message}{newline}&amp;#xA;Category: {category}{newline}&amp;#xA;Priority: {priority}{newline}&amp;#xA;EventId: {eventid}{newline}&amp;#xA;Severity: {severity}{newline}&amp;#xA;Title:{title}{newline}&amp;#xA;Machine: {localMachine}{newline}&amp;#xA;App Domain: {localAppDomain}{newline}&amp;#xA;ProcessId: {localProcessId}{newline}&amp;#xA;Process Name: {localProcessName}{newline}&amp;#xA;Thread Name: {threadName}{newline}&amp;#xA;Win32 ThreadId:{win32ThreadId}{newline}&amp;#xA;Extended Properties: {dictionary({key} - {value}{newline})}" name="Text Formatter" /&gt;
  &lt;/formatters&gt;
  &lt;categorySources&gt;
    &lt;add switchValue="All" name="General"&gt;
      &lt;listeners&gt;
        &lt;add name="Database Trace Listener" /&gt;
      &lt;/listeners&gt;
    &lt;/add&gt;
  &lt;/categorySources&gt;
  &lt;specialSources&gt;
    &lt;allEvents switchValue="All" name="All Events" /&gt;
    &lt;notProcessed switchValue="All" name="Unprocessed Category" /&gt;
    &lt;errors switchValue="All" name="Logging Errors &amp;amp; Warnings"&gt;
      &lt;listeners&gt;
        &lt;add name="Event Log Trace Listener" /&gt;
      &lt;/listeners&gt;
    &lt;/errors&gt;
  &lt;/specialSources&gt;
  &lt;/loggingConfiguration&gt;
  &lt;exceptionHandling&gt;
    &lt;exceptionPolicies&gt;
    &lt;add name="Policy"&gt;
      &lt;exceptionTypes&gt;
        &lt;add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="NotifyRethrow"&gt;
          &lt;exceptionHandlers&gt;
            &lt;add name="Logging Exception Handler" type="CustomExceptionLoggingHandler.CustomExceptionLoggingHandler, CustomExceptionLoggingHandler" logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" priority="0" /&gt;
          &lt;/exceptionHandlers&gt;
        &lt;/add&gt;
      &lt;/exceptionTypes&gt;
    &lt;/add&gt;
  &lt;/exceptionPolicies&gt;
  &lt;/exceptionHandling&gt;
  </code></pre>
  
  <p>EDIT: 
  Thanks to @lrb for getting me on the right path.  Here is the code that worked-</p>
  
  <pre><code>protected void Application_Start()
  {
      LoggingConfiguration loggingConfiguration = BuildLoggingConfig();
      LogWriter logWriter = new LogWriter(loggingConfiguration);
      Logger.SetLogWriter(logWriter, false);
      ExceptionPolicy.SetExceptionManager(exManager);
  
      // Create the default ExceptionManager object programatically
      exManager = BuildExceptionManagerConfig(logWriter);
  
      // Create an ExceptionPolicy to illustrate the static HandleException method
      ExceptionPolicy.SetExceptionManager(exManager);
  
             ...
  }
  
  private static LoggingConfiguration BuildLoggingConfig()
  {
      // Formatters
  
      var config = new LoggingConfiguration();
  
      return config;
  }
  
  private static ExceptionManager BuildExceptionManagerConfig(LogWriter logWriter)
  {
      var policies = new List&lt;ExceptionPolicyDefinition&gt;();
  
      var logAndWrap = new List&lt;ExceptionPolicyEntry&gt;
              {
  
                  new ExceptionPolicyEntry(typeof (Exception),
                      PostHandlingAction.ThrowNewException,
                      new IExceptionHandler[]
                       {
                         new WrapHandler("An application error has occurred.",
                           typeof(APIAvailabilityException))
                       })
              };
  
      policies.Add(new ExceptionPolicyDefinition("Policy", logAndWrap));
  
      return new ExceptionManager(policies);
  }
  </code></pre>