It really depends on the implementation of OBD2. What my 1997 Subaru logs (virtually nothing) compared to a 2015 Chevy Cruise are entirely different things.
However, in most cases, a Diagnostic Trouble Code (DTC) is logged with a freeze frame, which is a complete store of all Parameter ID's (PIDS). These parameters cover everything from RPM, vehicle speed, O2 sensor data, mass airflow data, long and short term fuel trims, ignition advance, intake and coolant temperature, and perhaps dozens more. These are accessed via OBD2 Mode 2. The simple "Pxxxx" DTC faults are accessed via OBD2 Mode 3, which is often the extent that simple consumer scan tools are able to display.
On more sophisticated scan tools, Mode 2 "freeze frame" data can be displayed, which is invaluable data as it reveals the exact running condition at the very instant the DTC code was set.
The history of such codes again varies with the implementation of OBD2, and quite likely how new the vehicle. On my 1997 Subaru, data is limited -- given that OBD2 wasn't a mandate until the 1996 model year.
However, all vehicles have two categories of DTC: "Pending", which is a detected fault, but doesn't set the Check Engine Light (CEL, SES) until the condition is detected again a certain number of times. (This is accessed through OBD2 Mode 7.) The number of "drive cycles" required to promote a "pending" to a CEL depends on the fault, the implementation, and the vehicle.
The other category of DTC is "stored" or "logged". These are true fault codes that have been promoted from "pending" status to a real-deal fault code, and they by OBD2 definition must set the CEL.
In addition, some Engine Control Units/Modules (ECU/ECM) have the capability of logging a few or dozens of "historical" fault codes, regardless if they have been repaired and/or cleared. This provides background to an astute technician, even when there is no current pending or logged DTC faults.
DTC codes do NOT have to be cleared "manually". If the condition that caused the fault is repaired, or simply no longer occurring (P0420 catalyst efficiency a classic example) the code will "clear itself" so to speak after a certain number of drive cycles without the fault reoccurring. The number of drive cycles required to clear an active CEL DTC depends on the fault and software implementation. In most cases, however, a technician clears these codes after a valid repair to assure the customer that the repair is complete. But we don't HAVE to; it's a courtesy. The ECU/ECM constantly monitors the PID and emission conditions, and will eventually relent, given enough "clean" drive cycles.
As an aside, there is a category of DTC that cause a FLASHING CEL. These differ dramatically from the "solid on" CEL, in that if it comes on and stays on, it's an indication that something is wrong, and the driver should seek service at a convenient opportunity. However, a FLASHING CEL indicates something severely wrong that could cause vehicle damage. Usually, this is indication of an overly rich condition, usually caused by severe ignition faults or fuel injection that if left alone could damage an expensive catalytic converter. These "flashing" check engine lights should be addressed immediately -- some OEMs suggesting pull the vehicle over and have it towed.
To further complicate this process, clearing a CEL gets rid of the fault code from the "active" category, but like your computer analogy, it's an ALT_CTRL-DEL. It completely resets the ECU/ECM, and clears out what is referred to as the "monitors".
The monitors are a whole plethora of tests which run either continuously, or in most cases when certain PID (temperature, engine load, fuel level, drive cycle) criteria are met. (This is what makes it particularly difficult to pass evaporative emission system monitors; the criteria are exact and even depend on how much fuel in in the tank.)
It takes a certain number of successful drive cycles, obeying all the requisite criteria, to "pass" these monitor tests. At this point the vehicle can pass an OBD2 emissions inspection -- when all monitors have passed. (In New York, vehicles produced prior to 2001 can have two incomplete monitor tests, 2001 and newer are allowed one, and it may be that recent vehicles are allowed none incomplete. This is just trivia.)
The upshot is that while a vehicle may have had proper repairs and the fault codes cleared, this does NOT mean it will pass an OBD2 emissions inspection. This prevents the shadetree technique of disconnecting the battery and taking it immediately to inspection. The vehicle must complete the requisite number of drive cycles with all (or most) criteria met in order to get the passing grade. While a so-called "not ready" vehicle doesn't fail emissions testing, it also doesn't pass. After the ALT-CTRL-DEL ECU/ECM lobotomy, the vehicle settles in and doesn't become "ready" for inspection until it proves to itself that all monitors are go, and the vehicle is running clean.