protected override void OpenFile()

in src/log4net/Appender/RollingFileAppender.cs [559:603]


  protected override void OpenFile(string fileName, bool append)
  {
    lock (LockObj)
    {
      fileName = GetNextOutputFileName(fileName);

      // Calculate the current size of the file
      long currentCount = 0;
      if (append)
      {
        using (SecurityContext?.Impersonate(this))
        {
          if (System.IO.File.Exists(fileName))
          {
            currentCount = new FileInfo(fileName).Length;
          }
        }
      }
      else
      {
        if (LogLog.IsErrorEnabled)
        {
          // Internal check that the file is not being overwritten
          // If not Appending to an existing file we should have rolled the file out of the
          // way. Therefore, we should not be over-writing an existing file.
          // The only exception is if we are not allowed to roll the existing file away.
          if (MaxSizeRollBackups != 0 && FileExists(fileName))
          {
            LogLog.Error(_declaringType, $"RollingFileAppender: INTERNAL ERROR. Append is False but OutputFile [{fileName}] already exists.");
          }
        }
      }

      if (!StaticLogFileName)
      {
        _scheduledFilename = fileName;
      }

      // Open the file (call the base class to do it)
      base.OpenFile(fileName, append);

      // Set the file size onto the counting writer
      ((CountingQuietTextWriter)QuietWriter!).Count = currentCount;
    }
  }