0

We have WebAPI project running under the ASP.NET MVC web application in IIS. We are basically using log4net in WebAPI for logging information to a text file (using rollingfileappender) and in ASP.NET MVC application, we are using AdoNetAppender to log all the required things in database. We are observing duplicate log files created e.g. FULL_December_26_2014.log AND FULL_December_26_2014.logFULL_December_26_2014.log and which should not be the case as we are hosted on single IIS with single worker process allowed for the application. We are seeing this issue for both instances of RollingFileAppender i.e. one is for Full and another is for Summary.

Here is some configuration - removed AdoNetAppender's parameter part for brevity:

<log4net debug="true">
    <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
      <bufferSize value="1" />
      <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <connectionString value="Data Source=DS;Initial Catalog=IC;Persist Security Info=True;User ID=UI;Password=*******;MultipleActiveResultSets=True" />
      <commandText value="INSERT INTO Log ([Date],[Level],[Logger],[User],[Message],[Exception],[DSSessionID],[LocationID], [UserID], [Method], [Status]) VALUES (@log_date, @log_level, @logger, @user, @message, @exception,@DSSessionID, @LocationID, @UserID, @Method, @Status)" />
    </appender>
  <appender name="Full" type="log4net.Appender.RollingFileAppender">
      <file value="F:\logs\Dev3\" />
      <rollingStyle value="Date"/>
      <datePattern value="'EpicBPA_FULL_'MMMM_dd_yyyy'.log'"/>
      <appendToFile value="true" />
      <maxSizeRollBackups value="5" />
      <maximumFileSize value="10MB" />
      <staticLogFileName value="false" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date - %message%newline" />
      </layout>
    </appender>
      <appender name="Summary" type="log4net.Appender.RollingFileAppender">
        <file value="F:\logs\Dev3\" />
        <rollingStyle value="Date" />
        <datePattern value="'SUMMARY_'MMMM_dd_yyyy'.log'"/>
        <appendToFile value="true" />
        <maxSizeRollBackups value="5" />
        <maximumFileSize value="10MB" />
        <staticLogFileName value="false" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%date{dd MMM yyyy HH:mm:ss}  - %message%newline" />
        </layout>
    </appender>
    <root>
      <priority value="ALL" />
      <level value="DEBUG" />
      <appender-ref ref="AdoNetAppender" />
    <appender-ref ref="Full" />
    </root>
    <category name="my.category">
      <priority value="DEBUG" />
    </category>
  <logger additivity="false" name="Summary">
          <level value="DEBUG"/>
          <appender-ref ref="Summary" />
      </logger>
  </log4net>

Can anyone guide me on what is wrong with it? It seems AdoNetAppender (responsible for logging in MVC application) writes to the RollingFileAppender's file when there is any error or exception occurs. But why?

gery128
  • 86
  • 5
  • Are you sure it's the AdoNetAppender causing the issue? Have you tried disabling the AdoNetAppender and see if the issue remains? I'm thinking of locking issue (see: http://stackoverflow.com/questions/1999382/intermittent-log4net-rollingfileappender-locked-file-issue?rq=1). – Herman Cordes Jan 05 '15 at 06:50
  • Thanks. I removed " " from root section and still facing the issue, so may be it's not about conflict between AdoNetAppender and RollingFileAppender. – gery128 Jan 06 '15 at 11:20
  • Please have a look at this blog: http://www.shamirc.com/2011/08/iis-75-aspnet-and-log4net-fileappender.html. – Herman Cordes Jan 06 '15 at 12:34
  • I am not facing any permission/locking issue. RollingFileAppender is writing to log file and so as AdoNetAppender inserting data in Log table. Problem is, I get duplicate files for single date as mentioned in question and I am not able to figure out why. – gery128 Jan 07 '15 at 14:21

1 Answers1

0

Your file is be using for other process, this is the reason, verify that you don´t duplicate the log4net instance