Chain is an exposed part that catches most dirt and needs regular cleaning and lubrication. There are many opinions on best lubricants and cleaning methods. Some people wipe the worst gunk off with a dry cloth, drip some oil on the links and call it a day. Some simply spray the chain with WD-40 which stops squeaks and doesn't catch dirt, but washes off quickly. Automotive heavy oil is not very good because it doesn't get deep enough into the links and is very sticky. Some people lubricate the chain after washing it thoroughly. The most effective procedure is to shake the chain in a glass of petrol/gasoline which degreases and washes off everything including dust between the links. Petrol can be used repeatedly, dust settles at the bottom and clean fluid can be poured elsewhere. Kerosene is not that good, it takes too long to dry. Water-based cleaning agents are probably similar in that regard (I haven't tested them personally because I'm afraid of corrosion). Chains can also be washed without being removed from the bike; either with a toothbrush and a cup of cleaner, or a special washing machine:
I have tried all of the above-mentioned techniques. Regardless of which one was used, all derailleur chains lasted more or less the same, about 2500..3000 km, so I ended up with the least labour-intensive cloth and oil way. Wide singlespeed chains last longer and since they wind around two fixed points, they can't slip even when considerably elongated, so I let them work for 10000 km or more, until they start to drag or produce suspicious noises.
Some colleagues recommend wax instead of oil, for example a mix of paraffine, bees' wax and grease at 1/1/1 ratio [source] (reported to last extremely long regardless of weather), paraffine and bees' wax at 8/1 ratio [source] (reported extreme chain life of tens of thousands kilometres, but needs more frequent reapplication) or something similar. The paraffin lubricates, bees' wax prevents it from flaking off, other components modify consistency and friction. Apply by immersing degreased chain into the molten mix for several minutes. Maybe I'll try it too some day.
Dirt affects the chain life a lot: dust and oil together make an abrasive paste which eats chain pins quickly when it gets to them. The biggest source of dirt on your chain (and shoes and trousers) is the front wheel; full-size mudguard and mudflap work wonders. Another exposed spot is next to rear tyre, a classic chainguard helps there. Long chains of RWD recumbents often hide in tubes (15◊1.5 mm polyamide pneumatic ones), which add some noise and resistance, but provide the second best cover right after fully sealed chaincase which can be seen on some singlespeed citybikes.
If it slips, fails to shift, drags, makes crunching noises, sticks to chainrings or looks ready to fall apart, it is definitely "dead" and probably has killed all cogs as well - new chain slips on worn teeth, so you have to replace the whole drivetrain. If you want your sprockets to last longer and stay compatible with new chains, replace old chain before it elongates too much (technically the elongation is caused by the pins wearing thinner). The threshold is somewhere around 132.8 mm, measured this way:
Or you can buy a special gauge which measures the same thing, just by sinking more or less deep between the links instead of giving you a number.
There is no law to prescribe chain maintenance (as long as a bike has both brakes, it needs no chain at all), so it's up to us to choose what to do. Should we replace the chain as soon as it shows first symptoms of wear to get the best efficiency and compatibility with new components? Or use it until it falls apart and then replace completely everything? Save partially worn chains and combine them with partially worn cassette which doesn't work with new chains? And what about RWD recumbents with a triple length chain that costs more than a cassette? I saw a recommended replacement interval of 1500 km in some handbook. Racing in mud can reduce chain life to mere hundreds of kilometres. Real-world examples? A 3/32" »Z chain on my Favorit road bike lasted about 5500 km (but it was too much, the most frequently used sprocket got worn too), Shimano UG lasted 2000 and Shimano HG about 2500. HG lasted less than 1300 km on my Python with short and poorly aligned drivetrain, and 2700 km on my Steelmachine with small chainring, good covering and easy angles. 1/8" »Z has clocked 6000 km so far on my citybike and 10000 on the folder (elongated beyond all reasonable limits, but didn't hurt the big thick sprocket at all). Anyway, chains are consumables that never last forever, so there's no point in spending too much of your life by excessive care.