Log4Net - WIll it be good to comment out the appneders

354 Views Asked by At

In my application I have a separate file appender for Errors and (Info and Debug). In production I just want to log the errors and disable the information and debug logs. Will keeping the appenders good way to do it, considering the performance in mind, or will it be bad for performance

  1. Keep the appenders but change the log level value to WARN inside the "root" tag

    <level value="WARN" />
    <appender-ref ref="FILE.ERROR" />
    <appender-ref ref="FILE.INFO" />
    
  2. Comment out the information appender from the "root" tag

    <level value="WARN" />
    <appender-ref ref="FILE.ERROR" />
    <!--<appender-ref ref="FILE.INFO" />-->
    

My logic says #2 is better because if we keep it enabled (as in #1) Log4net will initialize the appender, then for every log statement it will then compare the log level from the log statement vs the log level allowed by the appender and then take decision to log it or not. By using#2 we can avoid this loop and extra execution as the information appender will not be initialized at all.

My information appender has log level set as

<filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="DEBUG" />
        <levelMax value="INFO" />
</filter>

My question is my understanding from performance point of view valid? Or, it doesn't really matter for log4net, or may be log4net will not initialize the information appender as its log level does not match the root logger level viz. WARN

0

There are 0 best solutions below