Split Console.Out to a file and the console
I have a DatabasePopulator console program which uses my Fluent NHibernate layer to emit the basic database schema needed by an end-user program. I want to use it to generate the SQL and emit it to a file, so I can use it as the basis for an "upgrade" of a production DB without blowing the production data away (not a huge loss in this case, but still). I have it showing SQL on the console; I want to change the program开发者_JS百科 to attach a "file listener" that will collect the SQL statements, while still displaying the Console output. The problem is that I cannot do that directly; Console allows only one "listener", so I can't point Console itself to both StdOut and a file writer.
So, questions:
Does NHibernate send the SQL to the Trace output? If so, problem solved; I hook up a StreamWriter as a Trace listener and call it done.
Failing that, can I direct the SQL text output by NHibernate without setting up log4net? I've worked with that logger before and would prefer to avoid it, if NHibernate is sending the output to any built-in pipe besides Console.
Never mind. Found that the SchemaExport object can be told to generate a file, no listeners needed.
精彩评论