Optimal play on NxN boards where you need N in a row leads to a draw for all N > 2.
Contemporary Combinatorics, by Bela Bollobas has a proof of it. Below is a summary of this. The images below are from this book.
All board sizes 5x5 and up can be proven to be a draw by the second player employing a pairing strategy, namely where the second player plays a piece in a location next to or near the location of the first players move that most limits the options the first player has to play further.
For example, in the 5x5 game, optimal play for player 2 involves playing in the space with the same number as that played by player 1. If player 1 goes in the center, or if the matching space is already occupied, player 2 can go anywhere.
Similarly, for 6x6:
3x3 tic-tac-toe can be proven a draw by brute force method, and 4x4 can be proven a draw by creating 3 different pairing strategies based on each of the three possible opening moves by player 1 (ignoring symmetry and rotation).
So, under optimal play, there is no winning strategy.
However, if you want to write a good strategy, it seems the thing you want to do in general would be to play pieces that give you as many options to win as possible. This would be central locations at the beginning and locations that are part of multiple lines of your pieces in the mid-game and late-game. Early game, I'd go for spaces on the optimal move chart where the blocking move is the furthest away. Late game, I'd go for moves that win the game or block winning moves, and otherwise ones that give the most options in conjunction with existing pieces.