I ran into some issues trying to get log4net up and running on my current project, which is being written in VS2010 Beta2, targeting the .net 4.0 framework. I went about adding a reference to log4net, setup my app.config with a rolling log-file appender and added a call to XmlConfigurator.Configure() in one of my classes.
I then went to compile and got the following error: The type or namespace name 'log4net' could not be found (are you missing a using directive or an assembly reference?)
I double-checked, and yes, I had indeed added a reference to log4net, so what was wrong? Turns out, for .net 4.0 WPF projects, the default Target Framework is the “.Net Framework 4 Client Profile”, which is a subset of the full framework with the goal of shrinking footprint of the .net framework needed to download for a typical windows application. However, log4net apparently needs access to system.web.dll, which isn’t included in the client profile.
To fix your app so it’ll compile/run, open your project’s properties page, and set the Target Framework to “.Net Framework 4” and save your changes.
thank you so much.. i was about to die in despair :)
ReplyDeleteOk, so now no Logging on the client???
ReplyDeletethanks a lot
ReplyDeleteGreat tip.
ReplyDeletethanks I was pulling my hair out after I rebuilt my machine.
ReplyDeleteThanks, just a crazy bug/feature.
ReplyDeleteThanks, what a beating that was...
ReplyDeleteThanks for saving me a few hours! :)
ReplyDeleteThanks!
ReplyDeleteThanks!
ReplyDeleteHelped a lot, thank you!
ReplyDeletethanks a lot!
ReplyDeletesalvou meu dia!!!
You saved my day! Thanx a lot!
ReplyDeleteThank you so much for posting this!
ReplyDeleteThanks - i thought i was going crrrrrazy :-)
ReplyDeleteMore detailed answer here:
ReplyDeletehttp://tseonet.blogspot.com/2010/07/making-log4net-run-on-net-40.html
Thank you so much for this.
ReplyDelete@Gregorio: Good call, there's an extra step for it to run that tseo seems to get. Also http://www.codeproject.com/KB/dotnet/Log4NetWithClient.aspx shows you how to build it to work for the Client Profile...
ReplyDeleteThanks, this actually saved me. I have a 3rd party API that is a DLL and makes web service calls, so it needed the same fix. I couldn't understand why the reference was there but the messages implied they were not.
ReplyDeleteThanks!
ReplyDeleteThanks............!its working..........!
ReplyDeleteThanks a lot!!! :)
ReplyDeletethanks
ReplyDeleteafter a day of unnecessary work finally your post has solved my problem
thanks thanks thanks
Thanks yaar
ReplyDelete