I had that problem a couple of years ago, and after carefully cleaning the USB-C port with isopropyl alcohol I managed to solve it. I describe it here:
I haven’t had any problems with charging since then, but it’s true that I bought a silicone protector for the port (something like this), and I think that helps to keep it from getting dusty or wet, and from getting damaged.