If you would log to a different database than master, and that database has not yet become available, logins will fail.
To deal with the permissions issue, you should create a special login for the login trigger:
CREATE LOGIN LoginTriggerUser WITH PASSWORD = 'WhateverYouSeeFancy'
ALTER LOGIN LoginTriggerUser DISABLE
GRANT INSERT ON AuditTable TO LoginTriggerUser
Then you create the trigger with the EXECUTE AS clause:
CREATE TRIGGER logintri ON ALL SERVER WITH EXECUTE AS 'LoginTriggerUser' FOR LOGON AS
To get the name of the user logging in, you need to use the function original_login()
. SYSTEM_USER and similar function will return LoginTriggerUser.
I also have some text about logon triggers here: http://www.sommarskog.se/grantperm.html#serverlevelobjects (although here logging is done to a separate database).