Having spend, and I shit you not, a year of my life getting this to work, my short answer is; Dont.
We did logging to an SD card, using a circular buffer, and it WILL fail. The internal micro erases (on a 4G) card, 8MB when you want to modify a single 512byte sector. Also, if your writes are not at least 4K, the micro's internal wear leveling never wakes up, so you kill an area of the card.
Whilst it is cheap and abundant storage, it is a spectacularly bad idea to log binary info to SD cards in an embedded application. As Dimitry said, you cannot control the system, as the card's internal uC is running unknown firmware, and doing what it wants, when it wants, you might think you are shutting down "controlled", but the internal uC might think thats a great time to update its wear leveling, as it is inactive at that time, boom, corrupt data.
SD manufacturers are also not exactly truthful when it comes to R/W cycles, as the 100k they "claim" is when used by big files in an OS environment, with the files filling the card etc etc, ie, its a very certain set of variables under which the card will meet its spec. If you manage to get a straight answer out of them, you will be told that a typical 4GB SD card can only handle its flash being erased about 300 times, then your on your own in terms of data integrity, on a 32GB card, that number drops to ~30
My company is spending an eye watering amount of money to recall and replace client units with a new solution using NORFlash, as this gives us guaranteed 100k erase cycles.
So in short, plonk down a 64MByte NORFlash like the MX66F512, or a few even, and compress your logs in there. You will be saving yourself a shitload of time and money, and you do not have to worry about wear leveling in a normal application.