I have been a Christian for many years, but I was addicted to porn and I committed fornication against myself (my body). I never had sex with anybody, just myself. I have repented from that sin, and I recognize my sin, so do I need to confess my sin to God only or to my pastor?
Confession of wrong is always done before God (I John 1:9). See: Confessing Our Faults for details. God also encourages us to lean on our brethren when we are struggling with sin. See: How detailed does a confession of sin have to be? God does not require that such a confession needs to be made to a particular person, such as an elder or a preacher.
Pornography is a sin. See: A Look at Pornography and Lies Pornography Tells Men. However, masturbation is not fornication. Fornication is a sexual sin done with another person. See: Does "sexual immorality" (porneia) include masturbation?.