====== Error Log ======
__localisation Logs__
SELECT SERVERPROPERTY('ErrorLogFileName')
(No column name)
C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\Log\ERRORLOG
__lister les numéros de logs__
EXEC sys.sp_enumerrorlogs;
Archive # Date Log File Size (Byte)
0 11/24/2025 08:58 64986460
1 11/22/2025 23:57 7926818
2 11/22/2025 10:55 292378122
3 11/15/2025 23:57 808864
4 11/15/2025 23:03 484982
5 11/15/2025 23:01 5847440
6 11/15/2025 10:58 430784880
__Accéder aux logs__
//Exec xp_ReadErrorLog
<LogNumber>,
<LogType>,
<SearchItem1>,
<StartDate>,
<EndDate>,
<SortOrder>//
* **LogNumber**: It is the log number of the error log. You can see the lognumber in the above screenshot. Zero is always referred to as the current log file
* **LogType**: We can use this command to read both SQL Server error logs and agent logs
* 1 – To read the SQL Server error log
* 2- To read SQL Agent logs
* **SearchItem1**: In this parameter, we specify the search keyword
* **SearchItem2**: We can use additional search items. Both conditions ( SearchItem1 and SearchItem2) should be satisfied with the results
* **StartDate** and **EndDate**: We can filter the error log between StartDate and EndDate
* **SortOrder**: We can specify ASC (Ascending) or DSC (descending) for sorting purposes
EXEC xp_readerrorlog
1,
1,
N'log',
NULL,
N'2025-11-22 09:00:00.000',
N'2025-11-22 10:00:00.000',
N'desc'