禁用 Active Record 的 Log4Net 日志记录
如何禁用 Active Record 的 Log4Net 日志记录...?
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
</configSections>
<log4net debug="false">
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" >
<param name="File" value="C:\Projects\MyProject\bin\Log.txt" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n" />
</layout>
</appender>
</log4net>
全局.asax.cs
XmlConfigurationSource source = new XmlConfigurationSource("C:\Projects\MyProject \\ActiveRecord.xml");
ActiveRecordStarter.Initialize(source, typeof(User), typeof(Role));
log4net.Config.XmlConfigurator.Configure();
log.Info("Application Started");
How can I disable Log4Net logging for Active Record...?
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
</configSections>
<log4net debug="false">
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" >
<param name="File" value="C:\Projects\MyProject\bin\Log.txt" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n" />
</layout>
</appender>
</log4net>
Global.asax.cs
XmlConfigurationSource source = new XmlConfigurationSource("C:\Projects\MyProject \\ActiveRecord.xml");
ActiveRecordStarter.Initialize(source, typeof(User), typeof(Role));
log4net.Config.XmlConfigurator.Configure();
log.Info("Application Started");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想完全禁用日志记录,则可以关闭根记录器上的日志记录。
如果您只想禁用 Active Record,则需要找出 Active Record 正在使用的命名空间(或者,如果它们不遵循此约定,则找出 Active record 正在使用的记录器名称)。
如果是关于 NHibernate 那么下面的配置就可以了:
If you want to disable logging completely then you can turn logging off on the root logger.
If you want to disable only for Active Record you need to find out the namespace that Active Record is using (or if they did not follow this convention the logger name that Active record is using).
If it is about NHibernate then the following configuration does the trick: