What you call trench warfare probably appeared during the American Civil War, but I remember Tito Livio, a Roman author, saying that the digged trenches ay least during some of the sieges during the early republic, so the idea has been arround for some time.
Since the widespread use of gunpowder, earthworks (fortified pits or temporary walls constructed of pack earth or crop bales) had been used during sieges. These fortifications were used to protect the besieger's artilley from enemy retaliation.
They were also dug to a lesser extend for defending your ground against an enemy assault in the open, but this practice was widely frowned upon as dishonorable.
Notable use of these siege batteries and early trenches include the Ottoman siege of Vienna in 1692, The Battle of Bunker Hill, The Patriot's encirclement of Boston's British Garrison, The Siege of General Cornwallis leading to his surrender.
However, trench warfare in the modern sense as exemplified by the Western Front, was pioneered by the American Civil War and to a lesser extent the earlier Crimean War. Two battles can be examined to demonstrate this, the Siege of Vicksburg and the Siege of Sevastopol.
Vicksburg was one of the most important battles of the American Civil War and could be accurately described as the Civil War's Stalingrad. Starving confederate civillians and soldiers dug in trenches and slept in caves beneath the city. Near the end of the siege they had begun eating rats and cannibalism was not far off. The Union army dug in under General Ulysses S. Grant and fought to sever the confederate control of the Missisippi River by taking the vital hub of Vicksburg.
Sevastopol and the wider Crimean war was a microcosm of the future European warfare, as large armies fought face to face for small gains on the tiny Crimean Peninsula.
Other examples you could turn to for further research are the Russo-Turkish war of 1877, the Russo-Japanese War, the Italo-Ottoman war and the Balkan Wars.
Hope this answered your question!