How to do store Error Log in SQL Server Tables?

How to do store Error Log in SQL Server Tables?

CREATE PROCEDURE [dbo].[usp_Log_QDT_DataBase_Exception]
(
@emp_ID VARCHAR(8) = NULL,
@Manager_ID VARCHAR(20) = NULL,
@Web_Page_Name VARCHAR(50) = NULL,
@Function_Name VARCHAR(50) = NULL
)
AS
BEGIN
SET NOCOUNT ON;
BEGIN TRY
IF ERROR_NUMBER() IS NULL RETURN;--If no error number information
IF XACT_STATE() = -1
BEGIN
RETURN;
END
INSERT INTO Database_Error_Log(emp_ID, Manager_ID,Web_Page_Name,Function_Name,
ErrorNumber, ErrorSeverity, ErrorState,
ErrorProcedure, ErrorLine, ErrorMessage)
VALUES(@emp_ID, @Manager_ID,@Web_Page_Name,@Function_Name,
ERROR_NUMBER(),ERROR_SEVERITY(),ERROR_STATE(),ERROR_PROCEDURE(),ERROR_LINE(),ERROR_MESSAGE());
END TRY
BEGIN CATCH
RETURN -1;
END CATCH;
END;

No comments: