如何为log4net选择appender?
Nhibernate 使用 log4net 设置,当前正在登录到控制台。 我希望它保持这种方式。
我现在正在添加一个 fileappender。那么在我的代码中,如何创建一个新的记录器类并确保它使用这个 fileappender?
再次强调,我希望 nhibernate 继续使用我之前的配置,这是我原来的配置:
<log4net debug="false">
<appender name="console" type="log4net.Appender.ConsoleAppender, log4net">
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n"/>
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default priority -->
<root>
<priority value="INFO"/>
<appender-ref ref="console"/>
</root>
</log4net>
Nhibernate is setup using log4net, and is currently logging to the console. and I want it to keep it this way.
I am now adding a fileappender. So in my code, how to I create a new logger class and make sure it uses this fileappender?
Again, I want nhibernate to continue to use whatever I had before, here is my original config:
<log4net debug="false">
<appender name="console" type="log4net.Appender.ConsoleAppender, log4net">
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n"/>
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default priority -->
<root>
<priority value="INFO"/>
<appender-ref ref="console"/>
</root>
</log4net>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需将 fileAppender 添加到配置文件中,并在控制台后的根节点内添加对其的引用,两个附加程序将同时处于活动状态和工作状态。当然,假设 NHibernate 正在读取并使用该配置文件。
Just add your fileAppender to the config file and add a reference to it inside the root node after the console one and both appenders will be active and working at the same time. Assuming that NHibernate is reading and using that config file of course.