Similar to acoustic guitar recording, an amp and DI can each play a crucial role in the final result, and recording both (if possible) can provide some cool options. A microphone on your guitar cab or combo's speaker captures the air movement produced by the drivers and introduces your room's tone into the recording—how much room depends on mic type and placement. The electric guitar pickup serves as the electronic sound source emitting from the instrument. Among other things, pickups can boost and/or cut signals coming from the guitar. Pickups come in active and passive configurations and differ greatly in quality, behavior and affordability.
Do I need a DI box?
If you want to record your guitar cab or combo, as well as the direct signal from your guitar pickup, you have a couple of options. You can split the signal between your guitar amp/combo using a DI box—your guitar plugs into the DI box, with one output going to your head/combo and the other going to an external mic pre or the mic pre built into your recording interface. Alternatively, if your DI box is active, you can run that second output into the line input of your recording interface, bypassing the built-in preamp. If your guitar amp is equipped with a direct output (not to be confused with the speaker output), you also have the option of ditching the DI box altogether. Recording from the direct out or emulated output is an excellent option if you have a full-featured amp, as you will be using a very powerful preamp and have access to all the gain and equalization controls available on the amp channel. As is the case with everything else in recording, it all comes down to intent. Try the options available to you, then trust your ears to make the decision.
Recording tip: Don't have an amp? Have neighbors who will complain? In these cases, you have a whole world of virtual guitar amp software plug-ins on the market at some very affordable price points. When recording using these plug-ins, consider adding a microphone (dynamic for close miking, a condenser for distance miking) on the strings of your electric guitar. You will be pleasantly surprised by the added impact and authenticity this can provide. This also applies when recording through a real amp. Add a mic for the guitar strings. You will dig the results.