将 Console.Out 拆分为文件和控制台
我有一个 DatabasePopulator 控制台程序,它使用我的 Fluent NHibernate 层来发出最终用户程序所需的基本数据库模式。我想用它来生成 SQL 并将其发送到文件,这样我就可以使用它作为生产数据库“升级”的基础,而不会破坏生产数据(在这种情况下并不是一个巨大的损失,但仍然)。我让它在控制台上显示 SQL;我想更改程序以附加一个“文件侦听器”,该侦听器将收集 SQL 语句,同时仍显示控制台输出。问题是我不能直接这样做;控制台只允许一个“侦听器”,因此我无法将控制台本身指向 StdOut 和文件编写器。
那么问题来了:
NHibernate 是否将 SQL 发送到 Trace 输出?如果是这样,问题就解决了;我将 StreamWriter 连接为 Trace 侦听器并称其完成。
如果做不到这一点,我可以在不设置 log4net 的情况下直接由 NHibernate 输出 SQL 文本吗?我以前使用过该记录器,并且如果 NHibernate 将输出发送到除 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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没关系。发现SchemaExport对象可以被告知生成一个文件,不需要监听器。
Never mind. Found that the SchemaExport object can be told to generate a file, no listeners needed.