failed to initialize the system configuration vs2012

Topics: Logging Application Block
Sep 3, 2013 at 11:59 AM
Hi, I'm new to vs and have made my first project that worked fine until I started to add logging. Below my error, config file and part of the project code. Please help. Thanks, Jan

An unhandled exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.Configuration.dll

Additional information: failed to initialize the system configuration

My config file reads:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<connectionStrings>
<add name="ConnectionString" connectionString="Server=MINI\SQLExpress;DataBase=MUS6db;Integrated Security=SSPI"/>
</connectionStrings>
<appSettings>
<add key="ClientInterface_MessagePath" value="C:\MDS6\ClientInterface\Messages"/>
</appSettings>
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="Trace">
<listeners>
  <add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" source="Enterprise Library Logging" formatter="Text Formatter" log="" machineName="." traceOutputOptions="None"/>
  <add name="Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" fileName="c:\\MDS6\ClientInterface\Log\MUS.ClientInterface.log" header="" footer="" formatter="Text Formatter"/>
</listeners>
<formatters>
  <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" template="{category} {timestamp(local)} {message}" name="Text Formatter"/>
</formatters>
<logFilters>
  <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" enabled="true" name="Logging Enabled Filter"/>
  <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.CategoryFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" categoryFilterMode="DenyAllExceptAllowed" name="Category Filter">
    <categoryFilters>
      <add name="Error"/>
      <add name="Application"/>
      <add name="Configuration"/>
      <add name="Information"/>
      <add name="Trace"/>
    </categoryFilters>
  </add>
</logFilters>
<categorySources>
  <add switchValue="All" name="Application">
    <listeners>
      <add name="Flat File Trace Listener"/>
    </listeners>
  </add>
  <add switchValue="All" name="Configuration">
    <listeners>
      <add name="Flat File Trace Listener"/>
    </listeners>
  </add>
  <add switchValue="All" name="Error">
    <listeners>
      <add name="Flat File Trace Listener"/>
    </listeners>
  </add>
  <add switchValue="All" name="Trace">
    <listeners>
      <add name="Flat File Trace Listener"/>
    </listeners>
  </add>
  <add switchValue="All" name="Information">
    <listeners>
      <add name="Flat File Trace Listener"/>
    </listeners>
  </add>
</categorySources>
<specialSources>
  <allEvents switchValue="All" name="All Events"/>
  <notProcessed switchValue="All" name="Unprocessed Category"/>
  <errors switchValue="All" name="Logging Errors &amp; Warnings">
    <listeners>
      <add name="Event Log Listener"/>
    </listeners>
  </errors>
</specialSources>
</loggingConfiguration>
</configuration>

I get the error when I trace into line Logger.SetLogWriter(new LogWriterFactory().Create());

region Using directives

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.VisualBasic;

endregion

namespace MUS.ClientInterface
{
static class Program
{
    #region Main
    /// <summary>
    /// Program entry
    /// </summary>
    /// <param name="args">Optional commandline parameters</param>
    static void Main(string[] args)
    {
        //IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
        //LogWriterFactory logWriterFactory = new LogWriterFactory(configurationSource);
        //Logger.SetLogWriter(logWriterFactory.Create()); 

        Logger.SetLogWriter(new LogWriterFactory().Create()); 
        Logger.Write(String.Format("ClientInterface.ProcessFiles: Read config file"));
Sep 3, 2013 at 2:24 PM
Edited Sep 3, 2013 at 2:25 PM
It looks like the version number was not updated in the config file for all entries when moving from Version 5 to 6. Try replacing all occurrences of "Version=5.0.414.0" with "Version=6.0.000.0".

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Marked as answer by randylevy on 10/7/2013 at 11:02 PM
Sep 3, 2013 at 2:53 PM
Auch, should have caught that myself.
Thanks!
It's working now.