Audit.FileName Property


Gets the name of the file in which the audit log information is recorded, when the audit destination is a file.

Namespace:   Microsoft.SqlServer.Management.Smo
Assembly:  Microsoft.SqlServer.Smo (in Microsoft.SqlServer.Smo.dll)

public string FileName { get; }

Property Value

Type: System.String

A String value that specifies the name of the file in which the audit log information is recorded.

You can set the audit destination type using the P:Microsoft.SqlServer.Management.Smo.Audit.AuditDestinationType property.

The following code example shows how to get the name of the audit destination file.


using System;
using Microsoft.SqlServer.Management.Smo;

namespace samples
    class Program
        static void Main(string[] args)
            //Create the audit
            Server dbServer = new Server("(local)");
            Audit dbAudit = new Audit(dbServer, "Test Audit");
            dbAudit.DestinationType = AuditDestinationType.File;
            dbAudit.FilePath = "C:\\AuditDirectory";

            //Display the file name information on the console
            Console.Writeline("The audit filename is: " + 


#Create the audit
$dbServer = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")
$dbAudit = New-Object Microsoft.SqlServer.Management.Smo.Audit($dbServer, "Test Audit")
$dbAudit.DestinationType = [Microsoft.SqlServer.Management.Smo.AuditDestinationType]'File'
$dbAudit.FilePath = "C:\AuditDirectory"

#Display the file name information
Write-Host "The audit filename is:" $dbAudit.FileName
Return to top