The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.
| Author |
Messages |
|
Neil Haughton
 |
| 05/16/2008 5:18 PM |
|
Does anyone know how to use log4net.config files with Visual Studio 2008 unit testing?
I have a test project with a log4net.config file as part of the project, properties set to Content and Copy always, which diligently copies the config file to the bin\release or bin\debug folders on build. In the test class the [ClassInitialize] method includes this line:
log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo("log4net.config"));
which should point log4net to the executable folder for the test project, I thought. However the tests cannot find the config file: the log4net internal logging produces this message:
log4net: XmlConfigurator: configuring repository [log4net-default-repository] using file [log4net.config] watching for file updates
log4net: XmlConfigurator: configuring repository [log4net-default-repository] using file [log4net.config]
log4net: XmlConfigurator: config file [C:\Documents and Settings\Neil\My Documents\Visual Studio 2008\Projects\MatrixRoot\Matrix5\TestResults\Neil_DEVNH 2008-05-16 15_50_22\Out\log4net.config] not found. Configuration unchanged.
It seems to be looking for
…\TestResults\Neil_DEVNH 2008-05-16 15_50_22\Out\log4net.config
but I do not understand why. Well, I do understand, but the trouble is that this folder is a moving target and I don’t understand how to configure it to look in a stationary directory such as \bin\release.
Can anyone help with this puzzle?
TIA |
|
|
|
|
Neil Haughton
 |
| 05/16/2008 5:36 PM |
|
Okay – got it. All I needed to do in the test class was specify a relative path from the test project output to the folder where my common config file is located within the solution..
eg
log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(@"..\..\..\ProjectBeingTested\log4net.config"));
and it uses the same file regardless of where the test output is being generated.
Thanks to anyone who started looking into this!
|
|
|
|
|
|
| You are not authorized to post a reply. |
|
|
|
ActiveForums 3.7
|