There is no definitive answer to this question as it depends on a number of factors, including what you consider to be 'writing' and what qualifies as the 'longest'. For example, if we take the Bible as the longest book ever written, then it would have been composed over centuries by multiple authors. However, if we look at something like the Mahabharata - which is often cited as one of the longest works of fiction - it was written by a single author over the course of around 30 years.
In terms of sheer length, there are a number of contenders for the title of longest thing ever written. The Iliad and Odyssey combined are around 15,000 lines long, while Virgil's Aeneid clocks in at just over 12,000. The Mahabharata is even longer at around 100,000 verses, while an unfinished poem known as The Epic Of Gilgamesh is thought to be even longer still (although much of it has been lost).
However, these are all works of fiction. If we look at non-fiction works instead then there are some clear frontrunners. The Guinness World Records lists both Pliny's Natural History and Antonine Itinerary as being among the longest books ever written; Pliny's work consists of 37 books totaling 7 volumes while Antonine Itinerary comprises 24 volumes. Other contenders for this title include Livy's History Of Rome (142 books) and Julius Caesar's Commentaries On The Gallic War (8 books).
So what is the longest thing ever written? It depends on how you define 'writing' and what qualifies as 'long'. However, if we take into account both fiction and non-fiction works then there are a number who could lay claim to this record.