Reputation: 5655
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.
Upvotes: 8
Views: 12818
Reputation: 63183
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);
Upvotes: 0
Reputation: 91
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" />
Upvotes: 9