xp_logevent (Transact-SQL)
SQL Server 2012
Logs a user-defined message in the SQL Server log file and in the Windows Event Viewer. xp_logevent can be used to send an alert without sending a message to the client.
When you send messages from Transact-SQL procedures, triggers, batches, and so on, use the RAISERROR statement instead of xp_logevent. xp_logevent does not call a message handler of a client or set @@ERROR. To write messages to the Windows Event Viewer and to the SQL Server error log file within an instance of SQL Server, execute the RAISERROR statement.
The following example logs the message, with variables passed to the message in the Windows Event Viewer.
DECLARE @@TABNAME varchar(30) DECLARE @@USERNAME varchar(30) DECLARE @@MESSAGE varchar(255) SET @@TABNAME = 'customers' SET @@USERNAME = USER_NAME() SELECT @@MESSAGE = 'The table ' + @@TABNAME + ' is not owned by the user ' + @@USERNAME + '.' USE master EXEC xp_logevent 60000, @@MESSAGE, informational