tags:

views:

153

answers:

2

I'm seeing something really strange happening with some projects I'm working on.

I used log4net in an MVC web site and this was working great.

I then was working on a totally unrelated Console application which uses the SharePoint API and as soon as I include the following line (other lines don't cause the problem)

SPLimitedWebPartManager spWebPartManager = web.GetLimitedWebPartManager("http://blah/blah.aspx?PageView=Shared", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);

I get the following message in the console app

log4net:ERROR XmlConfigurator: Failed to find configuration section 'log4net' in
 the application's .config file. Check your .config file for the <log4net> and <
configSections> elements. The configuration section should look like: <section n
ame="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /
>
log4net:ERROR XmlConfigurator: Failed to find configuration section 'log4net' in
 the application's .config file. Check your .config file for the <log4net> and <
configSections> elements. The configuration section should look like: <section n
ame="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /
>

I get this twice after a small delay. The delay is probably the request to get the web part manager from the page but I'm not sure why this log4net error is showing up in this project. I've gone through the code and bin folders etc. and found no trace of any log4net mentions.

Any ideas why this might be happening?

+1  A: 

Is Log4Net in the GAC?

Does your application reference any external class libraries? Maybe one of these uses Log4Net and expects the client's config to be setup for Log4Net.

Joe R
Hmm not sure that this would make a difference, assemblies in the GAC can't output errors in applications that don't reference them in any way.
Ben Robinson
Totally agree. There must be a reference, it's just that with Log4Net in the GAC it might be less obvious - Graeme says he has "gone through the code and bin folders" but doesn't mention looking in the GAC.
Joe R
Just had a look in the GAC - nothing there. I checked what the download of log4web actually included and it was pretty much a dll and xml file. I put these in the bin folder of the MVC app and that's as much installation as I've done. I'd maybe expect some config files in the framework to be modified had I used an installer so very confused!
Graeme
To get log4net to work you'd also need to add some settings to your config file. This link has lots of examples - http://logging.apache.org/log4net/release/config-examples.html
Joe R
+3  A: 

On the basis that stuff cannot generate errors unless it is used in some way, there must be some indirect reference to log4net in there. Are you using any third party libraries that depend on log4net, or some kind of error handling library that uses it. The most likely explanation for the error is the line of code is throwing an exception which is being caught by an error handling routine that is trying to log the error using log4net and then can't becuase there is no log4net config.

Ben Robinson
That's it! The page which I am loading in that bit of code has a Bamboo Webpart on it called Data Viewer. When I was searching through all the code on my machine earlier, I noticed that Bamboo actually use log4net too in their product and so now it makes sense! It is their web part which is causing the issue. My web.config for my SharePoint instance needs to have the log4net config section added possibly (or it may already be there but since I'm accessing the page from a Console app, it may be trying to find the config in the Console app's app.config)Thanks for the help folks!
Graeme
Yes it would need the log4net stuff in the console app's app.config.
Ben Robinson