Disable Log4Net Logging for Active Recording

How to disable Log4Net logging for active recording ...?

  <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");
+3
source share
1 answer

If you want to completely disable logging, you can disable logging in the root log.

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

If you want to disable Active Record only, you need to find out the namespace that Active Record uses (or if they did not abide by this convention, the name of the log using the active record).

If we are talking 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>
+5
source

Source: https://habr.com/ru/post/1792041/


All Articles