共用方式為


Get-SPLogEvent

 

適用版本: SharePoint Foundation 2010, SharePoint Server 2010

上次修改主題的時間: 2015-03-09

傳回統一登入服務 (ULS) 追蹤記錄的結果。

Syntax

Get-SPLogEvent [-AssignmentCollection <SPAssignmentCollection>] [-AsString <SwitchParameter>] [-ContextKey <String[]>] [-Directory <String>] [-EndTime <DateTime>] [-MinimumLevel <String>] [-StartTime <DateTime>]

Get-SPLogEvent [-AssignmentCollection <SPAssignmentCollection>] [-AsString <SwitchParameter>] [-ContextKey <String[]>] [-EndTime <DateTime>] [-File <String>] [-MinimumLevel <String>] [-StartTime <DateTime>]

詳細描述

此 Cmdlet 包含一個以上的參數集。您可能只使用一個參數集中的參數,但不可以結合不同參數集的參數。如需如何使用參數集的詳細資訊,請參閱 Cmdlet Parameter Sets

Get-SPLogEvent Cmdlet 會傳回 ULS 追蹤記錄檔案中符合準則的記錄。如果未指定任何參數,會傳回所有記錄檔案中的所有記錄。請使用 StartTimeEndTime 參數,來篩選時間範圍。建議使用這些參數,將此 Cmdlet 的效能最佳化。

Parameters

參數 必要 類型 描述

AssignmentCollection

選用

Microsoft.SharePoint.PowerShell.SPAssignmentColletion

為能適當處置物件而管理物件。使用 SPWebSPSite 等物件可能會耗用大量的記憶體,因此在 Windows PowerShell 指令碼中使用這些物件時,必須適當地管理記憶體。您可以使用 SPAssignment 物件將物件指派給變數,並在不需要時處置這些物件,以釋放記憶體。使用 SPWebSPSiteSPSiteAdministration 物件時,若未使用指派集合或 Global 參數,將會自動處置這些物件。

注意

使用 Global 參數時,所有物件會包含在全域儲存區內。若未立即使用物件,或未使用 Stop-SPAssignment 命令處置物件,將會發生記憶體不足的狀況。

AsString

選用

System.Management.Automation.SwitchParameter

每筆記錄會傳回為獨立的字串

ContextKey

選用

System.String[]

指定內容資料應新增至指定的內容索引鍵結果,例如:-ContextKey @("UserName", "SiteName")。

Directory

選用

System.String

列出備用目錄中的記錄檔案 (即已設定 LogLocation 目錄之外的所有目錄)。

MinimumLevel

選用

System.String

傳回指定等級或更高等級的記錄。有效值為 ErrorWarning

EndTime

選用

System.DateTime

此類型必須是符合管理語言文化的有效 DateTime 格式,如美國英文的 2/16/2007 12:15:12。

File

選用

System.String

指定用以查詢記錄的特定檔案。

StartTime

選用

System.DateTime

此類型必須是符合管理語言文化的有效 DateTime 格式,如美國英文的 2/16/2007 12:15:12。

輸入類型

傳回類型

Example

--------------範例 1-----------------

Get-SPLogEvent -MinimumLevel "Warning"

此範例會傳回等於或高於預設記錄檔案目錄中警告嚴重性的所有記錄項目。

--------------範例 2-----------------

Get-SPLogEvent -Directory "C:\Logs" | Where-Object {$_.Level -eq "Warning"}

此範例會傳回 C:\Logs 目錄中記錄檔案的所有警告項目。

--------------範例 3-----------------

Get-SPLogEvent -StartTime "12/04/2007 17:00" -EndTime "12/04/2007 18:00"

此範例會傳回發生在特定時間範圍內的錯誤項目,這是美國特有的文化。

--------------範例 4-----------------

Get-SPLogEvent -ContextKey @("UserName" ,"SiteName")

此範例會傳回最近的記錄檔案內容,並新增指定的內容索引鍵資料。

--------------範例 5-----------------

Get-SPLogEvent | Where-Object {$_.Level -eq "Error" -and {$_.Area -eq "SharePoint Foundation "}

此範例會傳回所有與 SharePoint Foundation 有關的錯誤項目。

--------------範例 6-----------------

Get-SPLogEvent -ContextKey @("Name") | %{$_.ToString() + "'t" + $_.Context["Name"]}

此範例會傳回記錄檔案內容,並新增內容資料。

See Also

Reference

New-SPLogFile
Get-SPLogLevel