So I’ve seen a lot of questions around this issue with generally the only resolution being: “It’s a warning, just ignore this”. Whilst it is safe to do this, for pedants like me there is a true resolution. There are a few places around the net to get this but (like a lot of issues I blog about) you often need to combine the advice. Here’s the true resolution:
- Download the (unofficial) log4net XML Schema Definition (XSD) from http://csharptest.net/downloads/schema/log4net.xsd
- The the XSD to your project somewhere e.g. your Resources folder (if you have one)
- Restart Visual Studio (this may not be needed but some places recommend)
- Open your Log4Net.config file (or other file containing your Log4Net definition)
- With your XML file select look in your top menu for XML:
NOTE: This is only visible when your XML file is selected! - Select XML -> Schemas and an XML Schemas window pops up
- Locate your log4net.xsd and in the Use column select “Use this schema”
- Click OK
Your issue should now be resolved! This will, of course, work for other XML and XSD combos and not just for Log4Net. Hopefully now nobody will have this issue as the solution is all resolved in one neat location 🙂
15 replies on “How to remove warning: The ‘log4net’ element is not declared”
Thanks for sharing! =)
Hi Gerardo,
No problem, I’m glad you found it useful – thanks for your comment! 🙂
Easy & Works perfectly ! Many thanks !! 🙂
Thank Stephen!
Brilliant! No idea why everyone else makes this so hard – thanks for sharing!
Did everything like you mentioned. And now i have 79 Messages (as before) plus 1 Warning more (“The ‘doc’ element is not declared.”)…
Hi Reto,
That probably means that you have a number of other issues to resolve. To be honest, you don’t really need to resolve this issue – if you are comfortable with it then you can ignore it. It’s a balance between having no warnings and spending a lot of time resolving issues that may not really exist. Good luck!
Thanks sir, a few years later, but finally I could get rid of that annoying warning haha. Thanks for helping control freaks like me haha
Was not working until I looked at some of the sample config files
My log4netDefault.config file I added this to the top
and because I use this schema for my layout
–I got a warning it about this layout so:
In log4net.xsd
Find this line !
Add this line after
As if by Magic — Zero errors – Zero Warnings (250,000 line project 🙂
So call me clinical but I hate warnings
ok my last post has the XML lines removed,
Basically a few mods to my config file and the downloaded xsd file and
As if by Magic — Zero errors – Zero Warnings (250,000 line project Wooohooo)
So call me clinical but I hate warnings
Thank you very much for your Blog !
Hi Paul,
You’re very welcome, I’m really glad it could help – thanks for your feedback! 🙂
Steve
Thank you Stephen 🙂
You are most welcome, thanks for your comment! 🙂
Thanks for the blog post, helped! 🙂
Thank you for help! One small improvement instead of this fix. Add the reference to schema in log4net element: