{"id":1812,"date":"2019-06-10T01:28:02","date_gmt":"2019-06-10T01:28:02","guid":{"rendered":"http:\/\/www.theSQLReport.com\/?p=1812"},"modified":"2019-06-10T01:28:02","modified_gmt":"2019-06-10T01:28:02","slug":"finding-errorlog-file-directory-in-sql-server","status":"publish","type":"post","link":"https:\/\/www.theSQLReport.com\/?p=1812","title":{"rendered":"Finding Errorlog File Directory in SQL Server"},"content":{"rendered":"<p>Working with some new monitoring software, I need to locate the directory of the SQL Server&#8217;s Errorlog.\u00a0 This location is not standard and differs by each version of SQL Server.\u00a0 Note that pictured below is a test vitural machine, and I do not install SQL Server on the C &#8211; drive on any work related server.<\/p>\n<p>To find the SQL Server error log, I would query the &#8220;<strong>SERVERPROPERTY(&#8216;ErrorLogFileName&#8217;)<\/strong>&#8220;:<\/p>\n<pre>SELECT SERVERPROPERTY('ErrorLogFileName') \r\nAS 'ERRORLOG FILE LOCATION';<\/pre>\n<p><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2019\/06\/ErrorLogFileName.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1813 size-full\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2019\/06\/ErrorLogFileName.jpg\" alt=\"SERVERPROPERTY('ErrorLogFileName')\" width=\"640\" height=\"177\" srcset=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2019\/06\/ErrorLogFileName.jpg 640w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2019\/06\/ErrorLogFileName-300x83.jpg 300w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2019\/06\/ErrorLogFileName-210x58.jpg 210w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>To get the directory of SQL Server&#8217;s Errorlog, I would trim off the file errorlog file name:<\/p>\n<pre>SELECT \r\nleft( convert(nvarchar(500), SERVERPROPERTY('ErrorLogFileName')) , \r\nLEN (convert(nvarchar(500), SERVERPROPERTY('ErrorLogFileName')))- 8 ) \r\nas 'Errorlog Location';<\/pre>\n<p><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2019\/06\/ErrorLogFileDirectory.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1815 size-full\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2019\/06\/ErrorLogFileDirectory.jpg\" alt=\"Directory of SQL Server's Errorlog\" width=\"1010\" height=\"228\" srcset=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2019\/06\/ErrorLogFileDirectory.jpg 1010w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2019\/06\/ErrorLogFileDirectory-300x68.jpg 300w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2019\/06\/ErrorLogFileDirectory-768x173.jpg 768w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2019\/06\/ErrorLogFileDirectory-210x47.jpg 210w\" sizes=\"(max-width: 1010px) 100vw, 1010px\" \/><\/a><\/p>\n<p>To put the the directory of SQL Server&#8217;s Errorlog in something like a variable that could be used in a stored procedure:<\/p>\n<pre>DECLARE @Errorlog_Location nvarchar(500)\r\n\r\nSET @Errorlog_Location = \r\n'Errorlog Location: ' + \r\nleft( convert(nvarchar(500), SERVERPROPERTY('ErrorLogFileName')) , \r\nLEN (convert(nvarchar(500), SERVERPROPERTY('ErrorLogFileName')))- 8 )\r\n\r\nPRINT @Errorlog_Location<\/pre>\n<p><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2019\/06\/ErrorLogFileDirectory_Variable.jpg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1814 size-full\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2019\/06\/ErrorLogFileDirectory_Variable.jpg\" alt=\"Directory of SQL Server's Errorlog in something like a variable\" width=\"1015\" height=\"248\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Working with some new monitoring software, I need to locate the directory of the SQL Server&#8217;s Errorlog.\u00a0 This location is not standard and differs by each version of SQL Server.\u00a0 &hellip; <a class=\"readmore\" href=\"https:\/\/www.theSQLReport.com\/?p=1812\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":1814,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[159],"class_list":["post-1812","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql-server","tag-errorlog"],"_links":{"self":[{"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/posts\/1812"}],"collection":[{"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1812"}],"version-history":[{"count":4,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/posts\/1812\/revisions"}],"predecessor-version":[{"id":1819,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/posts\/1812\/revisions\/1819"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/media\/1814"}],"wp:attachment":[{"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}