'System.Configuration.ConfigurationErrorsException' occurred in Microsoft.Practices.EnterpriseLibrary.Logging.dll

Topics: Logging Application Block
Apr 21, 2009 at 8:13 AM
Edited Apr 21, 2009 at 8:16 AM
Hi,

I am trying to use the Loggin Application Block with a VC++ CLR project. Here is my code:

#include

"stdafx.h"

 

 

using

namespace System;

 

 

using

namespace Microsoft::Practices::EnterpriseLibrary::Common;

 

 

using

namespace Microsoft::Practices::EnterpriseLibrary::Logging;

 

 

using

namespace Microsoft::Practices::ObjectBuilder;

 

 

 

int main(array<System::String ^> ^args)

 

{

LogEntry ^log =

 

gcnew LogEntry();

 

log->EventId = 111;

log->Message =

 

"Sample Log Message";

 

log->Categories->Add(

 

"Trace");

 

Logger::Writer->Write(log);

 

 

//Console.WriteLine("log written");

 

 

 

return 0;

 

}

 


This code builds fine. But when I try to run this project I get this exception. I am not sure why. Please help:

 

 

 

 

Exception:

An unhandled exception of type 'System.Configuration.ConfigurationErrorsException' occurred in Microsoft.Practices.EnterpriseLibrary.Logging.dll

 

 

Additional information: The configuration section for Logging cannot be found in the configuration source.



Thank You,
-Bhaskar

 

 

 

 

Apr 21, 2009 at 8:27 AM
Edited Apr 21, 2009 at 8:27 AM
Hi,

Do you have a configuration file with your app? The configuration file contains the information that the Logging Application Block will need.

 http://msdn.microsoft.com/en-us/library/dd203279.aspx <- How to enter Logging Information to the config file.


Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Apr 21, 2009 at 8:48 AM
Hi,

Thank You for the response. I do have a configuration file and I have added it to my project. I am attaching my configuration file, in case you would want to look at it. I am a newbie at this.

Thank You,
-Bhaskar

________________________________

From: AvanadeSupport [mailto:[email removed]
Sent: Tue 4/21/2009 12:57 PM
To: Bhaskar Rao R.
Subject: Re: 'System.Configuration.ConfigurationErrorsException' occurred in Microsoft.Practices.EnterpriseLib... [entlib:53935]



From: AvanadeSupport

Hi,

Do you have a configuration file with you app? The configuration file contains the information that the Logging Application Block will need.

http://msdn.microsoft.com/en-us/library/dd203279.aspx <- How to enter Logging Information to the config file.


Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
[email removed] <mailto:[email removed]>

Read the full discussion online <http://entlib.codeplex.com/Thread/View.aspx?ThreadId=53935&ANCHOR#Post181628> .

To add a post to this discussion, reply to this email ([email removed] <mailto:[email removed]?subject=[entlib:53935]> )

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe <http://www.codeplex.com/site/discussions/thread/unsubscribe/53935> on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com
Apr 21, 2009 at 9:22 AM
Hi,

I assume that your application is a console. So, you have a config file with the console app. Try opening it with the "Enterprise Library Config Tool" which is integrated with your Visual Studio.

1. Right Click the config file -> Edit Enterprise Library Configuration
2. Once the App config is opened using the config tool, you can now add the Logging Application Block Config
3. Right Click the second to the Top Level Node (The one with the path to your config) -> New -> Logging Application Block

Doing that steps can get you logging because by default, adding the logging application block also add the FormattedEventLogTraceListener (which log to Event Log). 

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Apr 21, 2009 at 9:29 AM
I have already done that. My intention is to log to a file. And so I created Flat File Trace Listener. Also in the All Events section, I have set the Trace Listener reference to Flat File Trace Listener. Everything wrks until "Logger::Writer->Write(log);" this point. I am not sure why the application breaks after this. Am I missing something else here?
Apr 21, 2009 at 9:54 AM
Hi,

I'm not that familiar with C++, I just found out that C++ doesn't automatically copy the config file to the bin dir upon compile. So, here's what I did:
 
1. Right-click my "app.config" - > Properties
2. Click the Custom Build Step Node
3. In the Command Line Property I added this :   copy app.config "$(TargetPath).config"

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Apr 21, 2009 at 10:53 AM

Hi Valiant,

 

I did as you suggested. The problem still seems to persists. Adding copy app.config "$(TargetPath).config" this in the command line and building te project actually skips the custome build, because it expects value in the Outputs field. I tried giving a file name in that section, but it did not help. Instead it gave me an error "Error 105 error PRJ0019: A tool returned an error code from "Performing Custom Build Step"".

However, I would like to know, why we are having this approach. Do u believe that my application crashing has got something to do with the config file or its settings?

Apr 22, 2009 at 6:15 AM
Yes, it definitely can't find the configuration file.  Try this (it works for me), right click on your CLR Console app project, select Properties.  Go to Build Events -> Post Build Events.  Add the copy app.config "$(TargetPath).config" in the Command Line Property.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Apr 27, 2009 at 10:34 AM
Hi Sarah,

Your post was really helpful. That did the trick for me. Thanks a ton for your help!

-Bhaskar
Feb 26, 2010 at 9:42 PM

I have a wrapper dll with an app.config file compiled with it. When running from a foxPro app I get the same "The configuration section for Logging cannot be found in the configuration source".

Is it possible to use this with the app.config file compiled with the wrapper assembly (for security purposes)?

Do i have to have it in the same dir as the wrapper and the foxPro exe file rather than compiled?

Mar 1, 2010 at 2:09 AM

You must implement something like this in foxpro - http://blogs.msdn.com/tomholl/archive/2006/04/02/entlib2externalconfig.aspx

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com