http://www.sqlservercentral.com/blogs/mssqlfun/2012/09/17/how-to-log-sql-server-custom-error-in-windows-event-log-/

Printed 2014/12/20 12:31AM

How to log SQL Server Custom Error in Windows Event Log ?

2012/09/17

SQL server gives an option to log custom errors in windows event log. We have 2 options of achieving this.

Option 1 : Using xp_logevent

BEGIN TRY

SELECT 10/0

END TRY

BEGIN CATCH

PRINT ERROR_Message()

DECLARE @msg VARCHAR(100)

SELECT @msg = ERROR_Message()

–xp_logevent error_number , errormessage, severity (INFORMATIONAL, WARNING, or ERROR)

EXEC xp_logevent 60000, @msg, error

END CATCH

Option 2 : Using RAISERROR…..WITH LOG

BEGIN TRY

SELECT 10/0

END TRY

BEGIN CATCH

PRINT ERROR_Message()

DECLARE @msg VARCHAR(100)

SELECT @msg = ERROR_Message()



Copyright © 2002-2014 Simple Talk Publishing. All Rights Reserved. Privacy Policy. Terms of Use. Report Abuse.