在 Fluent NHibernate 中启用 log4net 时遇到问题
我需要配置 log4net 和 Fluent NHibernate 方面的帮助。似乎 log4net 正在启动,但我没有从 NHibernate/Fluent NHibernate 获得任何信息。我想要这些信息来调试错误的映射。
App.config 中的配置
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
<layout type="log4net.Layout.PatternLayout">
<param name="Header" value="[Header]\r\n" />
<param name="Footer" value="[Footer]\r\n" />
<param name="ConversionPattern" value="%d [%t] %-5p %c %m%n" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="ConsoleAppender" />
</root>
<logger name="NHibernate"
additivity="false">
<level value="ALL"/>
<appender-ref ref="ConsoleAppender"/>
</logger>
以下是我启动 log4net 和配置的方法。
log4net.Config.XmlConfigurator.Configure();
FluentConfiguration cfg = Fluently.Configure()
.Database(SQLiteConfiguration.Standard.ShowSql().InMemory())
.Diagnostics(x => x.Enable());
DbCtx.Source = new SessionSource(cfg.BuildConfiguration()
.Properties, new PSModel());
我遇到的异常是在 cfg.BuildConfiguration() 的最后一行。不过,我在日志中没有收到任何有关映射过程的条目。
预先感谢您的帮助。
I need help in configuring log4net and Fluent NHibernate. It seems log4net is starting, but I'm not getting any information from NHibernate/Fluent NHibernate. I want this information to debug faulty mapping.
Configuration in App.config
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
<layout type="log4net.Layout.PatternLayout">
<param name="Header" value="[Header]\r\n" />
<param name="Footer" value="[Footer]\r\n" />
<param name="ConversionPattern" value="%d [%t] %-5p %c %m%n" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="ConsoleAppender" />
</root>
<logger name="NHibernate"
additivity="false">
<level value="ALL"/>
<appender-ref ref="ConsoleAppender"/>
</logger>
Here's how I launch log4net and configuration.
log4net.Config.XmlConfigurator.Configure();
FluentConfiguration cfg = Fluently.Configure()
.Database(SQLiteConfiguration.Standard.ShowSql().InMemory())
.Diagnostics(x => x.Enable());
DbCtx.Source = new SessionSource(cfg.BuildConfiguration()
.Properties, new PSModel());
The exception I'm getting is in the last line on cfg.BuildConfiguration(). I don't get any entries in log on how mapping went, though.
Thank you in advance for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你想在 Visual Studio 的输出窗口中查看消息,你应该使用以下命令:
另外,要查看日志消息,你可能还想将 NHibernate 吐出的所有内容都扔到 LogFileAppender 中:
If you are wanting to see the messages in the output window in visual studio you should use the following instead:
Also to see the log messages you may want to throw everything NHibernate spits out into your LogFileAppender as well:
问题在于 Fluent NHibernate 中发生异常,因此 NHibernate 的日志记录无法启动。
The problem laid in the fact that exception occured in Fluent NHibernate therefore logging for NHibernate wasn't able to kick in.