So there were all the propaganda and speeches on the line of "Be home by Christmas" on the opening of World War I. Of course, we all know how that ended up when a conflict people suspect would take months took four years.
How quickly did the soldiers realize that things weren't going as well? Were there journals that stated one day like "We'll attack the Frenchie/Krauts, we're going to drive them outta here!" then the next entry is "We're going to be here a long, long time." Or like how they envisioned the war to be and then when the shelling started, their vision on their prospects took a complete turn no matter how optimistic the overall situation was?
Many important generals and military theorists had suspected that the next major European war would be a long one; these included two of the most controversial chiefs of the German General Staff, Schlieffen and the younger Moltke. Schlieffen had observed the extended length of tactical actions in modern wars -fourteen days at the Battle of Mukden in the Russo Japanese War against mere hours at Mars-La-Tour and Königgrätz- and that as such, campaigns might drag on indefinitely. In the highly integrated European economies of the period, it was believed that a war so protracted would bring widespread economic ruin. Briefing his commanders before the 1905 maneuvers, Schlieffen warned them how easily modern warfare could slip into a grinding positional struggle, and advised them to keep up a vigorous offensive tempo precisely to keep this from happening. In planning for a war with the French, he postulated that if the French retreated behind the Marne or Seine rivers without being enveloped by the German Army's right wing, the war would be endless.
By the end of the 19th century, it was increasingly believed that the size of modern armies, their logistical requirements, and the nature of their weapons made them difficult to destroy quickly; with the sheer number of men mobilized, it was possible for them to extend their frontage to the sea with ample reserves left over. Wars would become protracted struggles for positions, in which the determinant of victory would be a combatant's ability to endure.
Additionally, the experience in France in 1870 heralded the coming Volkskrieg, the national struggle for existence. As Moltke the Elder feared and Moltke the younger believed, wars would no longer be fought on the frontier, solely the domain of military professionals; all the resources of the nation would be mobilized, and an invading army could expect resistance through the whole depth of the hinterland. This would again protract the war; it would continue until the strength of the people on one side was finally broken.
One can see evidence of this in the first operations of 1914; when the German Army's right wing advanced through Belgium, it carefully avoided crossing through the Maastricht Annex (a thin strip of Dutch territory between Belgium and Germany) to avoid violating Dutch neutrality. This would allow Germany to continue importing vital supplies through the Netherlands; it was expected that Germany would be blockaded, but as long as the Netherlands remained neutral, neutral countries could ship goods into Dutch ports, which would then be purchased and transported over land into Germany. This policy was an impediment to German armies crossing through Belgium, and would not make sense unless Moltke the Younger was expecting a war that would last long enough for the continued importation of material to become relevant.
TL;DR: Before the war even began.
Antulio J. Echevarria II's book After Clausewitz: German Military Thinkers Before the Great War is an excellent guide to the theoretical understanding of war as it evolved in Germany between 1871 and 1914.