views:

25

answers:

1

I've set up my VSTO Excel add-in to use log4net for logging. Unfortunately I'm (seemingly) not able to make it configure itself from the app.config (which I deliver together with the add-in via ClickOnce).

I have read http://www.darinhiggins.com/?p=13 which lists some ways to get the file name of the app.config and then configure log4net with

log4net.Config.XmlConfigurator.Configure(fileInfo)

However the approaches this blog lists seem very error-prone to me (they "smell bad").

Things like

ConfigurationManager.GetSection

make me believe the .NET framework knows exactly where to get the file and there must be a way to retrieve this information from the framework instead of having to figure it out on my own. However, the XmlConfigurator in turn only accepts a file name, stream or xml node...

(Why I believe it's not working at the moment: I have configured it to use a RollingFileAppender with the file name being H:\Data\Debug.log, but after a GetLogger(...).Debug(...), there is still no Debug.log in place...). I have used the exact same configuration in other places, successfully.

A: 

XmlConfigurator.Configure(); uses the app.config file. That should work since the ConfigurationManager seems to be able to read the config file.

Stefan Egli
The referenced blog states: "...but unfortunately, since your VSTO addin is a DLL, log4net will, by default, look in the current app.config file, which, if you’re running in Word, for instance, will be WinWord.exe.config in the folder where WinWord.exe lives." - I want it to use the app.config I delivered via ClickOnce...
chiccodoro
How I was mistaken! This resource seems just to be completely wrong?? I've added your very line of code to my addin startup method and now it works fine! (If it was possible I'd be tempted to down-vote my own question...)
chiccodoro