The configuration section for Logging cannot be found in the configuration source
Asked Answered
C

2

8

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.

Capsicum answered 23/1, 2015 at 6:31 Comment(0)
A
9

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" />
Alage answered 6/2, 2015 at 3:28 Comment(0)
C
0

If you already set the configuration section in your web.config file, it might still fail with such an exception, as ConfigurationSourceFactory.Create() sometimes cannot parse the section.

A possible workaround is to use

IConfigurationSource configurationSource = new FileConfigurationSourceFactory(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
Cousingerman answered 5/9, 2018 at 16:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.