         // quit if log file is not large enough yet
         action = "get attributes of " + path
         let fileAttr = try fileManager.attributesOfItem(atPath: path)
-        let fileSize = fileAttr[FileAttributeKey.size] as! NSNumber
+        guard let fileSize = fileAttr[FileAttributeKey.size] as? NSNumber else { fatalError("Unknown type of size from fileAttr") }
         guard fileSize.intValue > rotationFileSizeBytes else {return}
 
         // form rotation file name

    ///
    func rotateFileAuto(cause: Rotation) {  // parameter unnecessary. for clarity only
      let fileManager = FileManager.default
      let path = writeToFileURL!.path

      // prepare parts of rotation file name for future use
      if (!rotateAutoCalledBefore) {


        // assemble a dictionary of date:file
        var fileDateMap = [Date: String]()
        guard let logFileDirectory = logFileDirectory else { fatalError("logFileDirectory is nil") }
        let iter = fileManager.enumerator(atPath: logFileDirectory)
        while let element = iter?.nextObject() as? String {
          let filePath = logFileDirectory + element
          action = "get attributes of " + filePath
          let fileAttr = try fileManager.attributesOfItem(atPath: filePath)
          let creationDate = fileAttr[FileAttributeKey.creationDate] as! Date
