Uploaded image for project: 'Log4net'
  1. Log4net
  2. LOG4NET-623

RollingFIleAppender creating multiple duplicate files within a process

    XMLWordPrintableJSON

    Details

    • Type: Task
    • Status: Reopened
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0.8
    • Fix Version/s: 2.1.0
    • Component/s: Appenders
    • Labels:
      None
    • Environment:
      Prod

      Description

      In a process I have multiple threads, each thread is creating a file with same log entries resulting in creation of multiple duplicate files within a process. This happens when multiple threads are trying to log same time.

      I am using RollingFIleAppender 

      RollingFileAppender appender = new RollingFileAppender

      { Name = configuration.LoggerName, Layout = patternLayout, AppendToFile = true, PreserveLogFileNameExtension = true, CountDirection = 1, RollingStyle = RollingFileAppender.RollingMode.Size, MaxSizeRollBackups = configuration.MaxRollBackups.HasValue ? configuration.MaxRollBackups.Value : 4, MaximumFileSize = configuration.MaxFileSizeKB.HasValue == false ? "100KB" : $"\{configuration.MaxFileSizeKB.Value}

      KB",
      StaticLogFileName = false,
      File = "myFile[%processid].log"
      };

       

      Upon digging turns out log4Net is thread safe but not process safe

      https://hectorcorrea.com/blog/log4net-thread-safe-but-not-process-safe/17

      Tried multiple locking mechanism which are offered by Log4Net itself for RollingFileAppender MinimalLock, InterProcessLock and ExclusiveLock none of them helped. Nor does PatterString help.

       

      Any ideas on how to solve the issue?

        Attachments

        1. image-2019-01-28-22-14-58-706.png
          77 kB
          Shrikant Mabrukar
        2. Log4Net_Appender1.png
          77 kB
          Shrikant Mabrukar
        3. Log4Net_Appender2.png
          77 kB
          Shrikant Mabrukar
        4. log4Net_createAppender.gif
          45 kB
          Shrikant Mabrukar
        5. Screen Shot 2019-01-22 at 11.41.48 PM.png
          91 kB
          Shrikant Mabrukar

          Activity

            People

            • Assignee:
              nachbarslumpi Dominik Psenner
              Reporter:
              shrikantm Shrikant Mabrukar
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: