As the title says, my dog keeps pooping and peeing in the flat. He knows it is not right because he has been taught and shown several times that he shouldn't, besides his behavior after it: He goes to a corner and keeps his head down, looking at us with the corner of his eyes and ears backwards, but never directly facing us.
What is weird is that when he does it in the flat, he makes sure we know it. He stands in front of us, or go to the center of the group and just do it, without any warning. I feel like he wanted to show us something or get attention somehow - but by doing this he gets the wrong kind of attention.
In regular situations, he asks to go out, he knows the drill: come, sit next to me and look straight into my eyes. If I don't get it, he starts to walk around from the main door to the balcony door. He knows I'll take him out if he do like this. I take him out around 3 times per day.
This dog was adopted from a foundation for homeless dogs, the vet says he's around 2, maximum 3 years old. They found him on the street with no signs of mistreating, just like he was lost or has been abandoned. He was adopted before us too, but the previous owner returned him because the house was smelling like dog (?).
We have a small 1 year old baby living with us. The dog is very attached to her and she likes to play with him too (and this is very nice to watch!), but he is jealous when she get attention from us, usually he's sitting in front of her in a way we can't (or he thinks we can't) see her. I've seen this behavior before with my parent's dogs (they own 4 of them, so I'm very used to dogs), he's also sleeping under her door at night, and he seems very concerned, or even scared, when she cries.
And finally, when we try to teach him that something he did was wrong, either by shouting at him, by making some loud noise (like slapping a shoe to the floor), or even just letting him smell the bag with his poop cleaned from the floor inside, he gets so scared that he pees himself every time, and goes to the corner, with the same behavior described earlier. And we are not shouting so hard at him neither making a very loud noise. This makes incredibly hard to teach him that he did something wrong.
I've grown up having dogs around me all the time, at least 3 of them, sometimes 5, since I remember. I think I had around 20 dogs my whole life, so I think I can say I know how to raise a dog in the right way. This dog is generally happy, likes to play with us and everything, but this behavior in particular is driving us crazy, and it really challenges me. I need some suggestions of how to end this, please.