简体   繁体   中英

Disable Log4Net logging for Active Record

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");

If you want to disable logging completely then you can turn logging off on the root logger.

<root>
    <level value="OFF" />
</root>

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:

<logger name="NHibernate" additivity="false">
    <level value="OFF"/>
</logger>
<root>
    <level value="DEBUG" />
    <appender-ref ref="LogFileAppender" />
</root>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM