I found this excellent blog post describing how to use SPWebConfigModifications with lessons leaned 
http://blog.beckybertram.com/Lists/Posts/Post.aspx?ID=131
Except from the blog.
Briefly, here's what the code does:
- It's not uncommon for you to try to add a new modification but then some error happens and it doesn't get flushed out to the web.config file, but it's still "stuck" in the list of modifications that needs to get made, so the next time you run your code, it's like SharPoint wants to flush all its entries so you end up getting that entry twice. I basically decided to head that off at the pass by simply removing all modfications right off the bat every time the feature is activated, leaving me with a clean slate. (Note, this approach may not be good in a web app where multiple apps might be writing to the web.config. In this case, I have complete ownership over my app so I know this is the only feature that will ever need to be writing to the web.config.)
- When the feature is deactivated, all the modifications are removed.
- This article on MSDN recommended using a new SPWebService.ContentService object to call the ApplyWebConfigModifications method. Strangely enough, this worked in a single-farm setting, but when I went to a load balanced farm, it stopped working. When I changed my code to use SPWebApplication.WebService object instead, it worked. Go figure.
I hope this saves someone else out there a bit of trouble!
Etiketter: MOSS, SharePoint, SharePoint 2010, web.config