Use RAISERROR command. There is an option for LOG.
Per BOL:
OPTION LOG
Logs the error in the error log and the application log for the instance of the Microsoft SQL Server Database Engine. Errors logged in the error log are currently limited to a maximum of 440 bytes. Only a member of the sysadmin fixed server role or a user with ALTER TRACE permissions can specify WITH LOG
Another way is to write a .NET CLR Procedure/Function/etc to call when error occurs to log the message to the Event viewer logs.