Events
Apr 8, 3 PM - May 28, 7 AM
Sharpen your AI skills and enter the sweepstakes to win a free Certification exam
Register now!This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to:
SQL Server
Logs a user-defined message in the SQL Server log file and in the Windows Event log. xp_logevent
can be used to send an alert without sending a message to the client.
Transact-SQL syntax conventions
xp_logevent { error_number , 'message' } [ , 'severity' ]
Important
Arguments for extended stored procedures must be entered in the specific order as described in the Syntax section. If the parameters are entered out of order, an error message occurs.
A user-defined error number larger than 50000
. The maximum value is 2147483647
(2^31 - 1).
A character string with a maximum of 2048 characters.
One of three character strings: INFORMATIONAL
, WARNING
, or ERROR
. severity is optional, with a default of INFORMATIONAL
.
0
(success) or 1
(failure).
xp_logevent
returns the following error message for the included code example:
The command(s) completed successfully.
When you send messages from Transact-SQL procedures, triggers, batches, and so on, use the RAISERROR
statement instead of xp_logevent
. xp_logevent
doesn't call a message handler of a client, or set @@ERROR
. To write messages to the Windows Event log and to the SQL Server error log file within an instance of SQL Server, execute the RAISERROR
statement.
Requires membership in the db_owner fixed database role in the master
database, or membership in the sysadmin fixed server role.
The following example logs the message, with variables passed to the message in the Windows Event Viewer.
DECLARE @@TABNAME VARCHAR(30),
@@USERNAME VARCHAR(30),
@@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;
Events
Apr 8, 3 PM - May 28, 7 AM
Sharpen your AI skills and enter the sweepstakes to win a free Certification exam
Register now!