At work I have the opportunity of working more or less in isolation: my boss is hands-off and I mainly speak with stakeholders here and there. I find this good for productivity and for meeting my targets, but at the same time if I don't do anything I will end up being isolated most of the time. There are a few colleagues I have nice chats with, but chats quickly turn into gossip, complaints about the company and assorted negativity. I am sure that these people in the end like their job, but when "speaking freely" I receive more information than I need. Sometimes it's good to know that a boss is not so good, but I don't think that this negativity does me good. I don't want to be isolated, but I want to avoid getting stressed by that negativity. How do you handle such a situation?
I generally will listen to them and figure out if they are venting or need advice.
If they are venting, just listen to them and when they are done talk about something else. Ask them questions about their lives, interests, etc. Tell them about yours. Eventually they will get to know more about you and possibly have some more common ground to talk about. This should lead to less conversations about work and more about life (hopefully positive!).
If they are looking for advice, then ask them questions that lead to something positive. For instance, if they are talking about somebody not being good at something, you might ask them if they could help that person get better. Maybe it's something they are lacking or they don't even realize it's an issue. Not only will you diffuse the situation you'll be somebody they can go to for advice as well.