Does anyone use MSTest and if so, have you had success in getting
logging to work with your tests?
Normally, in my application log4net is configured by a call to:
log4net.Config.XmlConfigurator.Configure(logConfigFile);
But, I'm writing tests for one of my library projects, so I don't see a
good place to put such a statement.
I thought I would try using the assembly attribute and an app.config
file to configure log4net, but this doesn't seem to work.
In a file called "Logging.cs" I have this;
using log4net.Config;
[assembly: XmlConfigurator()]
And my app.config looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings"
type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="SNIP.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<userSettings>
<SNIP.Properties.Settings>
<setting name="DefaultEnvironmentPath" serializeAs="String">
<valueSNIP\env\unittest</value>
</setting>
<setting name="ConfigurationFilename" serializeAs="String">
<value>SNIP.config.xml</value>
</setting>
<setting name="Log4NetConfigurationFilename" serializeAs="String">
<value>log4net.config.xml</value>
</setting>
</SNIP.Properties.Settings>
</userSettings>
<log4net>
<appender name="DetailedAppender"
type="log4net.Appender.FileAppender, log4net">
<file type="log4net.Util.PatternString" value="log4net.log" />
<appendToFile value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level %logger -
%message%newline" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="DetailedAppender" />
</root>
<logger name="NHibernate">
<level value="WARN" />
</logger>
</log4net>
</configuration>
Brian Pelton
J.G. Boswell Company
[EMAIL PROTECTED]