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

Topics: Logging Application Block
Nov 19, 2007 at 4:10 PM
Hi,
I am trying to run the EnterpriseLibs in my Application (Library), but each time I call Logger.Write(...) I get the following Error:

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

I have a file (App.config) and in there are the definitions I made through the Enterprise Library Configuration Tool. Of course App.config
is included in the project. But I didn't have made any further Configurations for the file in the Property window.

Any Idea, how I can solve these problem?

Thanks in Advance,
Omid

Here the configFile (App.config)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</configSections>
<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add fileName="trace.log" header="----------------------------------------"
footer="----------------------------------------" formatter="Text Formatter"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
traceOutputOptions="DateTime" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="FlatFile TraceListener" />
<add source="Enterprise Library Logging" formatter="Text Formatter"
log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Formatted EventLog TraceListener" />
</listeners>
<formatters>
<add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="FlatFile TraceListener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="FlatFile TraceListener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
</configuration>
Nov 20, 2007 at 2:41 PM
Hi,

What do you mean by "my Application (Library)"? You need an application and a configuration file for your application. In the base folder for your app you should have the "app name".exe and a matching "app name".exe.config; is that the case for your app?

Fernando
Nov 21, 2007 at 7:55 PM
my Application is a DLL. It's a part of an Application. There are many DLL's in these Project and I'd like to log the Output of each for debugging purposes.
Is it possible to use the EnterpriseLibs in DLLs??

regards,
Omid
Nov 22, 2007 at 11:31 AM
Regardless of how you structure your app, you will still need a configuration file for the application. You can use the the EL from any assembly, as long as the app using this assembly is properly configured for EL.

So what does your app's config file look like? Does the config file you pasted belong to the app's project or to the assembly's project?

Fernando
Nov 22, 2007 at 12:39 PM
The config file belongs to the assembly project. You can see it in my first posting at the beginning of these thread.
Are there any configuration in the project, which I have to do, like declaring as a resource or something else.

thanks in advance,
Omid
Nov 22, 2007 at 12:44 PM
As I mentioned in my previous 2 posts, EL's configuration needs to be in the application's configuration file. You can do some advanced configuration management when using some blocks, but not with the logging block.

Fernando
Nov 22, 2007 at 3:52 PM
Edited Nov 22, 2007 at 3:53 PM
App.config is the Application configuration file.

I have these project LogFacade with a Log class (the facade) and the App1.config which is the application configuration file
and now I would like to use these in the other projects in the Solution which are WPF projects....
Do I need an extra App config file for each project again???

Omid
Nov 22, 2007 at 4:51 PM
Hi Omid,

We need to clarify something. I'm talking about the application's configuration file, ie the config file for the exe. Your posts are rather confusing about how you're organizing your application (eg "my Application is a DLL. It's a part of an Application."), but it seems to me you're adding the app.config you pasted in your initial post to the VS project for the assembly where you use the EL, which is not your exe's assembly.

You can have an app.config item in your assembly's project, just like you can have any project item, but that is not the config file that will be used when the application is running. the config file that will be used is the file that is available in the folder where your exe runs and is named <exe name>.config; that's where you want your EL config.

If you have many applications, then you need several appropriately named configuration files matching each of the exe files.

Fernando

Nov 22, 2007 at 6:01 PM
Ok the .exe file is a WPF Project, so I have to put it into the App.xaml?!
By doing these I get 19 Errror, one of them:
"Error 50 The type 'configSections' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built."

<Application x:Class="VPSN.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml">
<Application.Resources>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</configSections>
<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
<listeners>
....

regards,
Omid
Nov 22, 2007 at 6:16 PM
Hi,

The app.xaml is a completely different file. If your app's exe is "my application.exe" then your configuration must go in "my application.exe.config". An app.config file in your application's project (not your library's project) will be copied to the output folder with the right name, if such a file exists.

Fernando
Jul 11, 2008 at 7:17 PM
I am having the same problem.
I am using a dll project type and I added a app.config file.
The bin\debug folder has a myappName.dll.config file

I am still getting the error "The configuration section for Logging cannot be found in the configuration source."

how do I fix this error?

Thank you.
Jul 11, 2008 at 10:42 PM
Hi,

Configuration files belong to applications, not dlls. If you have an exe it will be called [myapp].exe.config, and if it's a web app it will be a web.config file. How are you using your dll?

Fernando



AgentM wrote:
I am having the same problem.
I am using a dll project type and I added a app.config file.
The bin\debug folder has a myappName.dll.config file

I am still getting the error "The configuration section for Logging cannot be found in the configuration source."

how do I fix this error?

Thank you.


Jul 12, 2008 at 12:19 AM

I am using the Dll for a Powershell Cmdlet.

 

Jul 12, 2008 at 3:19 AM

I am trying to use the logging Application Block in a C# cmdlet.

 

Since Powershell runs in it’s own appdomain.

when I output the Appdomain values, the Appdomain.currentDomain  is “DefaultDomain” and the ConfigurationFile is “C:\Windows\system32\WindowsPowershell\v1.0\Powershell.config”

 

So, how do I change the configuration file path to the folder where the C# dll is located at and not to the Powershell folder?

 

Jul 14, 2008 at 5:25 PM

You can't just change the configuration file path, but you can spawn a new appdomain with a properly set configuration file (although I haven't tried that from a PowerShell cmdlet).

Alternatively, instead of using the Logging facade you could use the LogWriterFactory properly configured with a FileConfigurationSource pointing to your config file, which can have any name, to create a LogWriter for you. With this approach, you'd need to manage the LogWriter's lifetime yourself.

Fernando


AgentM wrote:

I am trying to use the logging Application Block in a C# cmdlet.

 

Since Powershell runs in it’s own appdomain.

when I output the Appdomain values, the Appdomain.currentDomain  is “DefaultDomain” and the ConfigurationFile is “C:\Windows\system32\WindowsPowershell\v1.0\Powershell.config”

 

So, how do I change the configuration file path to the folder where the C# dll is located at and not to the Powershell folder?

 




Jul 14, 2008 at 10:25 PM
Thanks Fernando,
I was able to get it to work by doing the following :-
1. Using the Fileconfiguration Source.
2. Copying all the required entlib's dll's to "C:\Windows\system32\WindowsPowershell\v1.0\”

I wish I could get away from (2).  But haven't found a way to do that yet. Do you have an idea ?
Jul 15, 2008 at 5:04 PM
Well, I had a nice answer but IE ate it, so here's the condensed version. You can:
  • GAC EntLib's assemblies (probably not an option in your case)
  • Spawn a new AppDomain with the ApplicationBase folder set to your snap-in's folder.
  • Add a handler to the AppDomain.AssemblyResolve folder to load EntLib's assemblies.

Hope this helps,
Fernando


AgentM wrote:
Thanks Fernando,
I was able to get it to work by doing the following :-
1. Using the Fileconfiguration Source.
2. Copying all the required entlib's dll's to "C:\Windows\system32\WindowsPowershell\v1.0\”

I wish I could get away from (2).  But haven't found a way to do that yet. Do you have an idea ?



Jul 21, 2008 at 11:10 PM
Thanks Fsimonazzi.
Do you have any code snippets on how to do this?
How do I set the ApplicationBase folder?

Jul 21, 2008 at 11:51 PM
These should help: http://msdn.microsoft.com/en-us/library/aehss7y0.aspx / http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx


AgentM wrote:
Thanks Fsimonazzi.
Do you have any code snippets on how to do this?
How do I set the ApplicationBase folder?




Sep 14, 2010 at 3:21 PM
fsimonazzi wrote:
Hi,

Configuration files belong to applications, not dlls. If you have an exe it will be called [myapp].exe.config, and if it's a web app it will be a web.config file. How are you using your dll?

Fernando

I know it's been a couple years now since this thread, but I just had to let you know that I was struggling with this problem for about a day and it wasn't until I read the above quote that the bell went off in my head.

Now it's working :)

Thanks,

--Matt