You can find some example in BOL:
http://technet.microsoft.com/en-us/library/bb326598.aspx.
Also there is an article on simple-talk:
http://www.simple-talk.com/sql/sql-server-2005/logon-triggers/.
Be careful when using APP_NAME to detect the program name - SSMS can use multiple names (e.g. "Microsoft SQL Server Management Studio - Query" can be the name for query window while Object Explorer can use another one). You can use Profiler to find out what the program names of all SSMS windows are. Or just use some LIKE logic to find all the patterns matching the template '%Management Studio%'.