Log4net configuration in GeneXus .Net application

Unofficial Content

Log4net default appender configuration for command line procedures is in log.console.config located at web directory of generated application. By default the RollingFileAppender is defined as follows:

<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
        <file  value="client.log"/>
          ...
        <lockingModel  type="log4net.Appender.FileAppender+MinimalLock"/>
  </appender>

Log4net default appender configuration for web application is in log.config. By default the RollingFileAppender is defined as follows:

<appender  name="RollingFile" type="log4net.Appender.RollingFileAppender">
        <file  value="client.log"/>
         ...
        <lockingModel  type="log4net.Appender.FileAppender+ExclusiveLock"/>
  </appender>

 

Locking model as MinimalLock means that a write lock on the file is acquired per log message, log entry writen and lock released. It is quite costly and thus will slow down the overall performance of the application because each message needs to wait for the write lock.

ExclusiveLock allows only one process to log to the file. The file is locked as long as the process exists that acquired the lock. This leads to optimal performance efficiency with respect to logging.

IIS Web Garden feature doesn’t work with ExclusiveLock by default unless you use unique log4net properties in constructing the file name so that is unique per IIS worker process. To make the log file names unique per instance change

<file value="client.log" />

to

<file type="log4net.Util.PatternString" value="client-%processid.log" />

Command line processes

As mentioned these processes use log.console.config to log execution. Default value is MinimalLock in order to avoid errors when running multiple processes at the same time. If this value is changed to ExclusiveLock the performance would be improved but only one process could be run at the same time.

Special case: running Database Reorganization process (this is a command line process) could mean to run more than one process at the same time, so the recommendation in this case is to have MinimalLock value to avoid errors.