{"id":61,"date":"2023-02-09T19:28:48","date_gmt":"2023-02-09T17:28:48","guid":{"rendered":"http:\/\/130.61.57.200\/?p=61"},"modified":"2023-04-12T09:55:13","modified_gmt":"2023-04-12T07:55:13","slug":"xp_readerrorlog","status":"publish","type":"post","link":"http:\/\/130.61.57.200\/index.php\/2023\/02\/09\/xp_readerrorlog\/","title":{"rendered":"xp_readerrorlog"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>## Exec xp_ReadErrorLog  LogNumber, LogType, SearchItem1, StartDate, EndDate, SortOrder\n##\n## 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\n## LogType: We can use this command to read both SQL Server error logs and agent logs\n## 1 \u2013 To read the SQL Server error log\n## 2- To read SQL Agent logs\n## SearchItem1: In this parameter, we specify the search keyword\n## SearchItem2: We can use additional search items. Both conditions ( SearchItem1 and SearchItem2) should be satisfied with the results\n## StartDate and EndDate: We can filter the error log between StartDate and EndDate\n## SortOrder: We can specify ASC (Ascending) or DSC (descending) for sorting purposes\n\nDECLARE @logFileType SMALLINT= 1;\nDECLARE @start DATETIME;\nDECLARE @end DATETIME;\nDECLARE @logno INT= 0;\nSET @start = cast( dateadd(day,-7,sysdatetime()) as datetime);\nSET @end = sysdatetime();\nDECLARE @searchString1 NVARCHAR(256)= &#039;Login&#039;;\nDECLARE @searchString2 NVARCHAR(256)= &#039;&#039;;\nEXEC master.dbo.xp_readerrorlog \n     @logno, \n     @logFileType, \n     @searchString1, \n     @searchString2, \n     @start, \n     @end;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[41,30],"class_list":["post-61","post","type-post","status-publish","format-standard","hentry","category-mssql","tag-errorlog","tag-log"],"blocksy_meta":[],"_links":{"self":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts\/61","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/comments?post=61"}],"version-history":[{"count":1,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts\/61\/revisions"}],"predecessor-version":[{"id":62,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts\/61\/revisions\/62"}],"wp:attachment":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/media?parent=61"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/categories?post=61"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/tags?post=61"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}