Ideally, you would use both the line out and the microphone simultaneously, and record the microphone on channel 1 and the amp’s line out on channel 2. That way, when you are mixing, you can either use channel 1 or channel 2 or a mixture of both. You might find that the best guitar sound for your mix is 80% microphone with 20% line out. If you record as 2 mono tracks you can get that with the faders, or if you record as one stereo track you can get that with the panner.
The way to record that is to put the microphone in front of the speaker and plug it into channel 1 of your interface, and run a line cable from the amp line out to channel 2 of your interface. Set the interface to receive a microphone input on channel 1 and line input on channel 2, which are very different kinds of gain.
There are various ways to place the microphone in front of the amp. Some people like to just hang the mic cable over the top of the speaker cabinet and let it dangle in front of the speaker. Others like to put the microphone on a stand and point it at the speaker, typically offset from the center of the speaker a bit. Where the microphone is placed with affect the sound quite a bit, so it is more a matter of taste than doing it right. You can research “microphone placement for guitar amp recording” and likely find many tips. Or just experiment with various microphone placements until your playback sounds the way you want it. A big thing is that the closer the microphone is to the speaker, the more bass you will get.
Also you typically will want to record the amp at a volume that is ideal for getting the sound you want.
If conditions are not ideal — i.e. the neighbors — you might still be able to get good results with the above setup at a lower volume. Your amp may have gain controls so that it can give you a “louder” sound at a lower volume. You can also put some baffles or blankets around the amp (not between the amp and the microphone) to reduce the volume the neighbors are going to hear while not reducing what the microphone hears.
However, it is not necessarily wrong to record the amp solely from the line out. Whether that gives you a good result depends on your amp, your taste, many factors.