The configuration section for Logging cannot be found in the configuration source

Vinay Joseph picture Vinay Joseph · Jan 23, 2015 · Viewed 10.5k times · Source

I get the following exception. I am using Enterprise Library 6.0 Application Logging Block.

    System.InvalidOperationException was unhandled by user code
  HResult=-2146233079
  Message=The configuration section for Logging cannot be found in the configuration source.
  Source=Microsoft.Practices.EnterpriseLibrary.Logging
  StackTrace:
       at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterFactory.LogWriterConfigurationBuilder.Create()
       at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterFactory.Create()
       at Logger..ctor() in \MBSLogger.cs:line 19
       at EventLoggingTest.test_log_simple_exception() in c:\Users\Vinay.Joseph\Documents\Visual Studio 2013\EventLoggingTest.cs:line 20
  InnerException: 

The code base is below.

       IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
        LogWriterFactory logWriterFactory = new LogWriterFactory(configurationSource);
        Logger.SetLogWriter(logWriterFactory.Create());


        if (!Logger.IsLoggingEnabled())
        {

        }
        else { 
            Logger.Write(new LogEntry(){
                Severity = System.Diagnostics.TraceEventType.Information,
                TimeStamp = DateTime.Now,
                Message = "Hello World"
            });
        }

Please tell me where I am going wrong.

Answer

Lance picture Lance · Feb 6, 2015

What does the app/web.config look like? Do you have the logging configuration setup?

<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />