It’s a delicate business, but it can be done well. Examples from published fiction that you might find of interest below.
I’ve also included a few examples from my own work — including a passage where I commit the very sin I’ve been talking about here.
A lot of the second novel in the Wilderness series takes place in lowland Scotland in 1802. The language spoken by the characters would have been Scots — not English. I’ll spare you the discourse on the difference at the moment, but while I was writing the novel I struggled with representing Scots in writing, and I did end up using spelling, to some degree. Here’s an example: