How to Change the SQL Server Agent Log File Path

By:   |   Comments (8)   |   Related: > SQL Server Agent


Problem

SQL Server Agent has its own log file that captures certain events from this service.  By default the file is located in the LOG folder where SQL Server is installed.  In this tip I will explain how to change the path of your SQL Server Agent log file "SQLAGENT.OUT" from an existing location to a new location.

Solution

We had a requirement to move the SQL Server Agent log file SQLAGENT.OUT from the current drive to a different drive. It was a part of our best practices in which we are streamlining our entire SQL Server environment. We made these changes by using two undocumented stored procedures.

  • SP_GET_SQLAGENT_PROPERTIES
  • SP_SET_SQLAGENT_PROPERTIES

The first stored procedure is used to retrieve the SQL Server Agent properties and the second stored procedure is used to set/change the properties for the SQL Agent service.

I strongly suggest testing any undocumented stored procedures in a lab environment first, before changing your production servers.

Steps to move the SQL Agent log file

Step 1

First check the existing location of the SQL Server Agent log file. Run the below undocumented stored procedure to get the current location. This stored procedure will let us know the SQL Agent properties of a particular server. This stored procedure can be found in the msdb database.

USE MASTER
GO
EXEC msdb..sp_get_sqlagent_properties
GO

We can see below the different settings that are returned when we run this command.  We are interested in the errorlog_file column for the change we need to make.  Here we can see the current location is the C drive.

Find the current location of sql server agent log file

Step 2

Now we will change the location of the file from the C drive to the G drive.

First we need to create the new destination folders where we want to put the SQLAGENT.OUT file. So, I created the folder "Microsoft SQL Server\MSSQL.1\MSSQL\LOG" on the G drive. If you do not create these folders you will have issues when the SQL Server Agent service restarts.

After the new folder has been created, run the below stored procedure to change the location.

USE MASTER
GO
EXEC msdb.dbo.sp_set_sqlagent_properties 
@errorlog_file=N'G:\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\SQLAGENT.OUT'
GO

Change the agent logfile location to different path

Step 3

Now we will verify whether the SQL Server Agent log file path has changed or not. We will be run the same command as in step 1 to get the SQL Server agent properties. We can see in the below screenshot that the path for the SQL Server Agent log file has been changed to the G drive.

Verify the change of agent log file location

Note, this change will not go into effect until you restart your the SQL Agent service. You can verify this by checking the new location to see if the file SQLAGENT.OUT exists or not.

Step 4

Now restart your SQL Server Agent service to bring the changes into effect. If you have any issues or the SQL Server Agent service does not start (you might get an error like below) then you should check the path you have set in step 2. The path has to be valid to successfully start this service.

Issue during SQL Agent service restart

Once the SQL Server Agent service successfully restarts you can check the new location of the SQL Server Agent log file. You should now see that the SQLAGENT.OUT file has been created in the new location which we have set in step 2.

log file creation in new location
Next Steps

Follow this process to move your SQL Server Agent log file SQLAGENT.OUT to some other location. If you want to explore more knowledge on SQL Server Agent then take a look at the tips about SQL Server Agent.



sql server categories

sql server webinars

subscribe to mssqltips

sql server tutorials

sql server white papers

next tip



About the author
MSSQLTips author Manvendra Singh Manvendra Singh has over 5 years of experience with SQL Server and has focused on Database Mirroring, Replication, Log Shipping, etc.

This author pledges the content of this article is based on professional experience and not AI generated.

View all my tips



Comments For This Article




Wednesday, March 15, 2023 - 7:10:20 AM - Oleksandr Back To Top (91012)
you can also change it using the “-e” startup parameter of the SQL Server service

Sunday, February 16, 2020 - 4:01:22 PM - Anex Back To Top (84551)

Thank you!!! 


Wednesday, January 3, 2018 - 12:14:23 PM - Burt Ward Back To Top (74715)

 Very Helpful, thank you!

 

 


Monday, December 4, 2017 - 5:42:04 AM - Sandip Parmar Back To Top (73601)

Hi,

I have two SQL Server 2014 instance which are running in different locations. One is in East india and second one is located in South India. Now i want to test SQL Replication test whether it is performing or not. But let me clear you, i have only read only permission in both SQL servers.

send me steps to check SQL replication. waiting for your reply.

Sandip Parmar.

 


Thursday, August 31, 2017 - 3:20:08 PM - Sean Perkins Back To Top (65674)

What is the best practice for the location of these logs? 

 

 


Friday, July 22, 2016 - 4:18:51 AM - Achim Stienen Back To Top (41946)

 Good article.

Be sure that the new log path exists and the SQLAgent service account has sufficiant permissions on that path.

Otherwise, the SQLAgent service will not start and there is no way to change the path using msdb.dbo.sp_set_sqlagent_properties because the SP needs the SQLAgent service running.

 You can change the path outside SQL in the registry by setting the HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\\SQLServerAgent\Errorlogfile value data to the correct file path + '\SQLAGENT.OUT'

 

 


Sunday, December 8, 2013 - 10:33:02 PM - manu Back To Top (27736)

Good one undocumented stored procedures are useful..


Tuesday, November 5, 2013 - 2:00:29 PM - Srinath Back To Top (27402)

Nice one..Learnt an item today !!















get free sql tips
agree to terms