Read SQL Server Error Log
mssql_error_logRead SQL Server ERRORLOG or Agent logs via sp_readerrorlog, filter lines by search strings, select archived files, and return newest entries first for troubleshooting.
Instructions
Error log: read the SQL Server ERRORLOG (or SQL Server Agent log) via sp_readerrorlog. Optionally filter to lines containing one or two search strings (e.g. "Backup", "3013") and select an archived log file. Returns newest entries first. Needs VIEW ANY ERROR LOG (SQL Server 2022+ / Managed Instance) or securityadmin. Not available on Azure SQL Database.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| logType | No | 1 = SQL Server error log (default), 2 = SQL Server Agent error log. | |
| maxRows | No | Cap on rows returned, newest first (default 100, max 1000). | |
| search1 | No | Only return lines containing this string (e.g. "Backup"). | |
| search2 | No | Further narrow to lines that also contain this string (e.g. "3013"). Applied in addition to search1. | |
| logNumber | No | Which log file: 0 = current ERRORLOG, 1 = most recent archive, 2 = next older, etc. Defaults to 0. |