sp_ReadErrorlog call examples
-- Reads SQL Server error log from ERRORLOG.1 file EXEC xp_ReadErrorLog 1 -- Reads current SQL Server error log EXEC xp_ReadErrorLog 0, 1 -- Reads current SQL Server Agent error log EXEC xp_ReadErrorLog 0, 2 -- Reads current SQL Server error log with text 'Failed' EXEC xp_ReadErrorLog 0, 1, 'Failed' -- Reads current SQL Server error log with text ‘Failed’ AND 'Login' EXEC xp_ReadErrorLog 0, 1, 'Failed', 'Login' -- Reads current SQL Server error log with text ‘Failed’ AND ‘Login’ from 01-Jan-2016 EXEC xp_ReadErrorLog 0, 1, 'Failed', 'Login', '20160101', NULL -- Reads current SQL Server error log with text ‘Failed’ AND ‘Login’ between 01-Jan-2012 and 30-Jan-2016 EXEC xp_ReadErrorLog 0, 1, 'Failed', 'Login', '20160101', '20160130' -- Reads current SQL Server error between 01-Jan-2016 and 30-Jan-2016 EXEC xp_ReadErrorLog 0, 1, NULL, NULL, '20160101', '20160130' -- Reads current SQL Server error for the last 48 hours declare @datefrom datetime , @dateto datetime select @datefrom = dateadd(hour,-48,CONVERT(varchar, GETDATE(), 112)) , @dateto = getdate() EXEC xp_ReadErrorLog 0, 1, N'FAILED', NULL, @datefrom, @dateto, N'DESC'