HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Is there a way to query SQL Server 2005/2008 for location of its log files?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
2008logsqlquerywayits2005filesforserver

Problem

I there a way to query SQL Server 2005+ for the file system location of its various log files. By that I mean the text log files, not database transaction log files?

For example my SQL Agent, Error Logs and maintenance plans all write to a folder called:

D:\MSSQLData\MSSQL.1\MSSQL\LOG


It's this folder I need to find the name of.

Updated:

As well as hunting SQL Books I had a poke around the registry under

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer


and

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MSSQLSERVER`


but nothing jumps out at me.

I'd also like an "official" way to achieve this and would rather not rely on undocumented features.

Solution

SELECT REPLACE(CAST(SERVERPROPERTY('ErrorLogFileName') AS nvarchar(512)), 'ERRORLOG', '')


EDIT: Cleaned it up a bit with a little more googling to verify; Also to note that this particular argument "ErrorLogFileName" to the SERVERPROPERTY function is undocumented and therefore unsupported by Microsoft. Use at your own risk. etc. etc.

Code Snippets

SELECT REPLACE(CAST(SERVERPROPERTY('ErrorLogFileName') AS nvarchar(512)), 'ERRORLOG', '')

Context

StackExchange Database Administrators Q#12705, answer score: 7

Revisions (0)

No revisions yet.