The exemption applies to the years the property was genuinely your principal residence, so if any portion of that 30 years involved renting out the whole home or a legal secondary suite, the Canada Revenue Agency may prorate the exemption and tax the gain for that portion of ownership.
Selling costs are separate from the tax question. Legal fees typically run $800 to $1,500, and total seller closing costs run 4 to 6 percent of the sale price, and those come off your proceeds regardless of how the capital gains exemption applies.
Because the exemption depends on your specific history of use, a tax professional should confirm your situation before you list. Get your hand-reviewed valuation from Joel Dyck.