SPBackupRestoreInformation.Log method (SPBackupRestoreLogSeverity, String)

Grava um erro, aviso ou mensagem informativa para o arquivo de log de administração.

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

Syntax

'Declaração
Public Sub Log ( _
    severity As SPBackupRestoreLogSeverity, _
    message As String _
)
'Uso
Dim instance As SPBackupRestoreInformation
Dim severity As SPBackupRestoreLogSeverity
Dim message As String

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

Parâmetros

Comentários

Este método é usado principalmente em implementações de manipuladores de evento da interface IBackupRestore .

Examples

O exemplo a seguir mostra como usar o método Log em uma implementação do método OnRestore .

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

Ver também

Referência

SPBackupRestoreInformation class

SPBackupRestoreInformation members

Log overload

Microsoft.SharePoint.Administration.Backup namespace