Logs a user-defined message in the SQL Server log file and/or in the Windows NT Event Viewer. When sending messages from Transact-SQL procedures, triggers, batches, and so on, use the RAISERROR statement instead of xp_logevent. If raising an error to the client is not desired, xp_logevent can be used to send an alert without sending a message to the client.
xp_logevent error_number, message, [severity]
where
The xp_logevent extended stored procedure does not call a client's message handler or set @@ERROR. To write messages to the Windows NT Event Viewer and/or to the SQL Server error log file with SQL Server 6.0, you can execute the RAISERROR statement. For details, see the RAISERROR statement.
This example logs the message (with variables passed to the message) in the Windows NT Event Viewer.
DECLARE @tabname varchar(30) DECLARE @username varchar(30) DECLARE @message varchar(255) SELECT @tabname = 'titles' SELECT @username = USER_NAME() SELECT @message = 'The table "' @tabname '" is not owned by the user "' @username '."' EXEC xp_logevent 60000, @message, informational
Execute permission defaults to the system administrator and can be granted to other users.
RAISERROR |