2008-07-18 @ 3:08:18 EDT
For those that don’t know me so well, I need you to read a post entitled The Quirkbook on Rands in Repose.
Truth be told, at least 4 out of 5 of those listed and the comments following (or ones very like them) are quirks I grew up with. I’ve worked and worked to get rid of most of them, but more come to fill their space, or they just morph into something less obvious to an observer.
Up until reading that, the only people I’ve encountered with similar issues were actors, portraying crazy people.
2008-07-11 @ 1:34:59 EDT
I’d mentioned on Dave Laribee’s Test Your NHibernate Mappings! post that you can use a custom log4net appender to catch the messages NHibernate outputs on initialization. Here’s a bit more detail.
First, the custom ListAppender class:
class ListAppender
: log4net.Appender.AppenderSkeleton
{
private List<LoggingEvent> _events = new List<LoggingEvent>();
public List<LoggingEvent> Events
{
get { return _events; }
}
protected override void Append(log4net.Core.LoggingEvent loggingEvent)
{
_events.Add(loggingEvent);
}
}
And a sample unit test:
[Test]
public void TreatNHibernateWarningsAsFailures()
{
ListAppender appender = new ListAppender()
{
Threshold = log4net.Core.Level.Warn,
};
log4net.Config.BasicConfigurator.Configure(appender);
string myConfigPath = @"wherever\you\put\your\NHibernate\config.xml";
Configuration config = new Configuration().Configure(myConfigPath);
using (ISessionFactory factory = config.BuildSessionFactory())
{
// Spin up the factory and then throw it away. We just want to guarantee that initialization has occurred.
}
if (appender.Events.Count == 0)
{
return;
}
StringBuilder errors = new StringBuilder();
errors.Append("Warnings/errors issued when starting up NHibernate:");
foreach (log4net.Core.LoggingEvent ev in appender.Events)
{
errors
.AppendLine()
.AppendFormat("\t{0}: {1} - {2}", ev.Level, ev.LoggerName, ev.RenderedMessage);
}
Assert.Fail(errors.ToString());
}