﻿SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE OR ALTER PROCEDURE auditlog.uspLogError
    @ErrorLogID int = 0 OUTPUT -- contains the ErrorLogID of the row inserted
AS                             -- by uspLogError in the ErrorLog table
DECLARE 
    @error_number INT =  ERROR_NUMBER(),
    @error_severity INT = ERROR_SEVERITY(),
    @error_state INT = ERROR_STATE(),
    @error_procedure SYSNAME = ERROR_PROCEDURE(),
    @error_line INT = ERROR_LINE(),
    @error_message NVARCHAR(4000) = ERROR_MESSAGE();

SET NOCOUNT ON;
INSERT auditlog.ErrorLog (
    UserName, 
    ErrorNumber, 
    ErrorSeverity, 
    ErrorState, 
    ErrorProcedure, 
    ErrorLine, 
    ErrorMessage
) VALUES (
    CURRENT_USER, 
    @error_number,
    @error_severity,
    @error_state,
    @error_procedure,
    @error_line,
    @error_message
);
SET @ErrorLogID = SCOPE_IDENTITY();
GO