Compartilhar via


SPBackupRestoreInformation.Log Method (SPBackupRestoreLogSeverity, String)

Writes an error, warning, or informational message to the administration log file.

Namespace:  Microsoft.SharePoint.Administration.Backup
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaration
Public Sub Log ( _
    severity As SPBackupRestoreLogSeverity, _
    message As String _
)
'Usage
Dim instance As SPBackupRestoreInformation
Dim severity As SPBackupRestoreLogSeverity
Dim message As String

instance.Log(severity, message)
public void Log(
    SPBackupRestoreLogSeverity severity,
    string message
)

Parameters

Remarks

This method is primarily used in implementations of the event handlers of the IBackupRestore interface.

Examples

The following example shows how to use the Log method in an implementation of the OnRestore method.

[C#]

public Boolean OnRestore(Object sender, SPRestoreInformation args)
{
    if (args == null)
    {
        throw new ArgumentNullException("args");
    }

    // If the CriticalFiles object was deleted from the farm after it was
    // backed up, restore it to the configuration database.
    CriticalFiles cf = SPFarm.Local.GetChild<CriticalFiles>(this.Name);
    if (cf == null)
    {
        this.Update();
        args.Log(SPBackupRestoreLogSeverity.Verbose, this.Name + " added back to configuration database.");
    }

    Boolean successSignal = true;

    // TODO: The following loop restores files to the local server. If there are 
    //       multiple front end servers, your code must iterate through all of 
    //       SPFarm.Local.Servers and restore the same files to every server whose
    //       Role property is SPServerRole.WebFrontEnd

    foreach (String path in FrontEndFilePaths)
    {
        FileInfo backupCopy = new FileInfo(path);
        FileInfo file = new FileInfo(args.Location + @"\" + backupCopy.Name);
        try
        {
            file.CopyTo(path, true);
            args.Log(SPBackupRestoreLogSeverity.Verbose, "Restored " + file.Name);
        }
        catch (Exception e)
        {
            args.Log(SPBackupRestoreLogSeverity.Verbose, file.Name + " not restored: " + e.Message);
            successSignal = false;
        }
    }
    
    args.CurrentProgress = 50;
    return successSignal;
}
Public Function OnRestore(ByVal sender As Object, ByVal args As SPRestoreInformation) As Boolean
    If args Is Nothing Then
        Throw New ArgumentNullException("args")
    End If

    ' If the CriticalFiles object was deleted from the farm after it was
    ' backed up, restore it to the configuration database.
    Dim cf As CriticalFiles = SPFarm.Local.GetChild(Of CriticalFiles)(Me.Name)
    If cf Is Nothing Then
        Me.Update()
        args.Log(SPBackupRestoreLogSeverity.Verbose, Me.Name & " added back to configuration database.")
    End If

    Dim successSignal As Boolean = True

    ' TODO: The following loop restores files to the local server. If there are 
    '       multiple front end servers, your code must iterate through all of 
    '       SPFarm.Local.Servers and restore the same files to every server whose
    '       Role property is SPServerRole.WebFrontEnd

    For Each path As String In FrontEndFilePaths
        Dim backupCopy As New FileInfo(path)
        Dim file As New FileInfo(args.Location & "\" & backupCopy.Name)
        Try
            file.CopyTo(path, True)
            args.Log(SPBackupRestoreLogSeverity.Verbose, "Restored " & file.Name)
        Catch e As Exception
            args.Log(SPBackupRestoreLogSeverity.Verbose, file.Name & " not restored: " & e.Message)
            successSignal = False
        End Try
    Next

    args.CurrentProgress = 50
    Return successSignal
End Function

See Also

Reference

SPBackupRestoreInformation Class

SPBackupRestoreInformation Members

Log Overload

Microsoft.SharePoint.Administration.Backup Namespace