Search code examples
c#asp.netlog4netasmx

When do I need to specify log4net.Appender.FileAppender.LockingModel in ASMX services


We have a project which consists of 3 different ASMX service files for example Service1.asmx, Service2.asmx, and Service3.asmx all of which are running from the same application pool.

We've just started using log4net to log our requests and responses, and it seems to be logging every request and response for each service correctly in the same log file (which is what we want).

However, on reading log4net config examples, I've seen some examples that are using log4net.Appender.FileAppender.LockingModel.

Do I need to consider this in my scenario? This is my current code:

   public class Global : System.Web.HttpApplication
   {
        public static readonly log4net.ILog asmxDebugLog = log4net.LogManager.GetLogger("AsmxDebugLogFile");
    
        protected void Application_Start(object sender, EventArgs e)
        {   
            log4net.Config.XmlConfigurator.Configure();     
        }  
   }  

In my web.config file I have

  <configuration>
     <configSections>
      <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
   </configSections>

  <log4net debug="true">
      <appender name="AsmxDebugLogFile" type="log4net.Appender.RollingFileAppender">
        <file value="App_Data/log4net_ASMX.DEBUG_"  type="log4net.Util.PatternString"  />
        <appendToFile value="true" />
        <rollingStyle value="Composite" />
        <datePattern value="yyyy-MM-dd'.log'" />
        <staticLogFileName value="false" />
        <maximumFileSize value="5GB" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
        </layout>
      </appender>
      <logger name="AsmxDebugLogFile">
        <level value="DEBUG" />
         <appender-ref ref="AsmxDebugLogFile" />
       </logger>
    </log4net>
  </configuration>

We are logging like this

  asmxDebugLog.Debug("Log something useful");

Solution

  • You only really need to care about locking when the loggers are not all in one process, which for you it seems they are (1 app pool ~= 1 process).

    The default locking mode is 'exclusive', which is fastest, so you don't need to (or want to) change that (and slow it down).

    If you later split the services into different app pools, you can then choose either InterProcess (if all on the same machine) or Minimal.