Hi all,

 

I'm currently in the process of trying to figure out how to use SQL Server
Compact Edition for the viewer database and ran into some problems where if
I could read the logs from NHibernate, it would help me out a lot. 

 

I'm getting an ADOException being thrown from NHibernate when I try to
update the database in the RebuildDatabase utility. Try as I might, though,
I could not get the NHibernate logs to show up in the file system. When I
run the viewer application, the logs show up fine, and I can see all the SQL
statements being generated by NHibernate. When I run RebuildDatabase,
however, they would not show up. Both applications use the CC Framework
call, Platform.Log, for application-specific logging, but even that wouldn't
work in RebuildDatabase, so I knew it wasn't a NHibernate configuration
problem.

 

After 1.5 hours of tinkering, I finally found the problem.

 

log4net configuration is loaded and applied per assembly that references it.
In the case of RebuildDatabase, the first assembly that is loaded and
references log4net is NHibernate. Since I don't have an NHibernate-specific
configuration for log4net, (".does not have a RepositoryAttribute
specified") the default repository is created and used, which logs to the
console (if it exists) or the Trace system (output window in Visual Studio).
Then, here's the crucial part, any subsequent assemblies that are loaded and
that do not have their own log4net configuration will use the *existing*
default repository. 

 

ClearCanvas.Common is the next assembly to be loaded, and it does not have
an assembly-specific log4net configuration, but it *does* have a "default"
repository configuration that writes log messages to a file (an appender).
This is *not* used, however, because a default repository already exists, so
the existing one is used instead, directing all log messages to Trace.

 

To confirm my hypothesis, I quickly added a line of code that would use
Platform.Log right at application startup, to ensure that ClearCanvas.Common
is loaded before NHibernate, and sure enough, the log messages now show up
in the log file.

 

 

Clinton

 

 

_______________________________________________
dev mailing list
[email protected]
http://clearcanvas.ca/mailman/listinfo/dev_clearcanvas.ca

Reply via email to