在 SharePoint Server 中設定診斷記錄Configure diagnostic logging in SharePoint Server

摘要: 了解如何從 SharePoint 管理中心網站或使用 Windows PowerShell 來設定 SharePoint Server 2013 和 SharePoint Server 2016 的診斷記錄。Summary: Learn to configure diagnostic logging in SharePoint Server 2013 and SharePoint Server 2016 from the SharePoint Central Administration website or by using Windows PowerShell.

必要條件Prerequisites

從 管理中心 執行此程序的使用者帳戶必須是 SharePoint 伺服器陣列管理員群組的成員。The user account that is performing procedures from Central Administrationmust be a member of the Farm Administrators SharePoint group.

診斷記錄設定的最佳作法Diagnostic logging setting best practices

在初始部署或升級後,以及若對環境做出變更,SharePoint Server 環境可能需要組態診斷記錄的設定。下列清單中的指南可協助您建立特定環境的最佳作法。The SharePoint Server environment might require configuration of the diagnostic logging settings after initial deployment, after upgrade, and if a change is made to the environment, such as adding or removing a server. The guidelines in the following list can help you form best practices for the specific environment.

  • 變更伺服器寫入記錄的磁碟。Change the drive to which the server writes logs.

    根據預設,SharePoint Server 會將診斷記錄寫入本身安裝所在的相同磁碟和磁碟分割。因為診斷記錄會使用大量的磁碟空間,而影響磁碟效能,因此建議您設定 SharePoint Server 寫入至未安裝 SharePoint Server 的其他磁碟。您也應該要考慮 SharePoint Server 寫入記錄之磁碟的連線速度。如果設定詳細資訊層級記錄,則伺服器會記錄大量的資料。因此,遲緩的連線可能會導致記錄效能不佳。By default, SharePoint Server writes diagnostic logs to the same drive and partition on which it was installed. Because diagnostic logging can use a large amount of drive space and compromise drive performance, you should configure SharePoint Server to write to another drive on which SharePoint Server is not installed. You should also consider the connection speed to the drive on which SharePoint Server writes the logs. If verbose-level logging is configured, the server records a large amount of data. Therefore, a slow connection might result in poor log performance.

  • 限制記錄的磁碟空間使用量。Restrict log disk space usage.

    根據預設,診斷記錄可使用的磁碟空間是不受限制的。因此,尤其若將記錄設定為寫入詳細資訊層級的事件時,請限制記錄使用的磁碟空間。當達到磁碟限制時,SharePoint Server 會在記錄新的記錄資料前,移除最舊的記錄。By default, the amount of disk space that diagnostic logging can use is unlimited. Therefore, restrict the disk space that logging uses, especially if you configure logging to write verbose-level events. When the disk reaches the restriction, SharePoint Server removes the oldest logs before it records new logging data.

  • 謹慎使用詳細資訊設定。Use the Verbose setting sparingly.

    您可以將診斷記錄設定為記錄詳細資訊層級的事件。這表示 SharePoint Server 會記錄所採取的每個動作。詳細資訊層級記錄會快速使用磁碟空間,而影響磁碟與伺服器的效能。您可以在做出重要變更時,使用詳細資訊層級記錄以記錄更多細節,然後在做出變更後將記錄重新設定為僅記錄較高層級的事件。You can configure diagnostic logging to record verbose-level events. This means that SharePoint Server records every action that it takes. Verbose-level logging can quickly use drive space and affect drive and server performance. You can use verbose-level logging to record more detail when you are making critical changes and then reconfigure logging to record only higher-level events after you make the change.

  • 定期備份記錄。Regularly back up logs.

    診斷記錄包含重要的資料。因此,定期備份記錄可確保此資料被保留下來。在限制記錄的磁碟空間使用量時,或如果只將記錄保留幾天的時間,則在達到臨界值時,SharePoint Server 將自動刪除記錄檔案 (從最舊的檔案開始)。Diagnostic logs contain important data. Therefore, back up the logs regularly to ensure that this data is preserved. When you restrict log drive space usage, or if you keep logs for only a few days, SharePoint Server automatically deletes log files, starting with the oldest files first, when the threshold is met.

  • 啟用事件記錄檔湧入保護。Enable event log flooding protection.

    啟用此設定時,SharePoint Server 會偵測 Windows 事件記錄檔中的重複事件,並在狀況回復至一般狀態時才不再隱藏重複事件。When you enable this setting, SharePoint Server detects repeating events in the Windows event log, and suppresses them until conditions return to a typical state.

您可以設定事件記錄檔和追蹤記錄檔的診斷記錄層級。這會限制可寫入每個記錄檔的資訊類型和數量。下表定義事件記錄檔和追蹤記錄檔可用的記錄層級:You can set the level of diagnostic logging for the event log and for the trace log. This limits the types and amount of information that are written to each log. The following tables define the levels of logging that are available for the event log and trace log.

事件記錄檔層級Event log levels

層級Level 定義Definition
None
不會記錄。No logging occurs.
重要Critical
此訊息類型表示發生嚴重錯誤,導致解決方案重大失敗。This message type indicates a serious error that has caused a major failure in the solution.
錯誤Error
此訊息類型表示緊急狀況。您應調查所有錯誤事件。This message type indicates an urgent condition. You should investigate all error events.
警告Warning
此訊息類型表示可能需要加以留意的潛在問題。您應檢視並追蹤一段時間內所發生的警告訊息,以找出其模式。This message type indicates a potential problem or issue that might require attention. You should review and track warning messages for patterns over time.
資訊Information
不需對資訊訊息採取任何動作。不過該訊息對監視解決方案的狀態提供寶貴的資料。Information messages do not require any action. However, they can provide valuable data for monitoring the state of your solution.
詳細資訊Verbose
此事件記錄檔層級會記錄冗長的事件或訊息。This event log level corresponds to lengthy events or messages.

追蹤記錄檔層級Trace log levels

層級Level 定義Definition
None
不寫入追蹤記錄檔。No trace logs are written.
未預期Unexpected
此層級會記錄的訊息是有關導致解決方案停止處理的事件。設定為此層級時,記錄檔會包括未預期、例外狀況、判斷提示和重要層級的事件。This level records messages about events that cause solutions to stop processing. When set to this level, the log will include events at the Unexpected, Exception, Assert, and Critical levels.
可監控Monitorable
此層級會記錄的訊息是有關限制解決方案的功能,但未停止應用程式之所有無法復原的事件。設定為此層級時,記錄檔也會包括「未預期」設定所記錄的事件。This level records messages about all unrecoverable events that limit the functionality of the solution but do not stop the application. When set to this level, the log also includes events that the Unexpected setting records.
High
此層級會記錄所有未預期但未停止解決方案處理的事件。記錄檔設定為此層級時,記錄檔也會包括「可監控」設定所記錄的所有事件。This level records all events that are unexpected but which do not stop the processing of a solution. When set to log at this level, the log also includes all events that the Monitorable setting records.
Medium
設為此層級時,追蹤記錄檔會包括除了「詳細資訊」和 VerboseEx 訊息之外的所有訊息。此層級會記錄所有有關所執行操作的高階資訊。此層級提供了足夠的詳細資訊,可建構資料流程和操作順序。系統管理員或支援專業人員可使用此記錄層級對問題進行疑難排解。若設為此層級,記錄檔也會包括「高」設定所記錄的所有事件。When set to this level, the trace log includes all messages except Verbose and VerboseEx messages. This level records all high-level information about operations that were performed. This level provides enough detail to construct the data flow and sequence of operations. Administrators or support professionals could use this level of logging to troubleshoot issues. When set to this level, the log will also include all events that the High setting records.
詳細資訊Verbose
若設為此層級,記錄檔會包括大部分動作。詳細資訊追蹤會產生很多記錄訊息。此層級通常僅用於開發環境的偵錯作業。記錄檔若設定為此層級,記錄檔也會包括「中」設定所記錄的所有事件。When set to this level, the log includes most actions. Verbose tracing produces many log messages. This level is typically used only for debugging in a development environment. When set to log at this level, the log will also include all events that the Medium setting records.
VerboseExVerboseEx
此層級僅由 Set-SPLogLevel PowerShell Cmdlet 支援,且會包括極低層級的診斷資料。只應在開發環境中使用此層級。若定為此層級,記錄檔也會包括「詳細資訊」設定所記錄的所有事件。 This level is only supported by the Set-SPLogLevel PowerShell cmdlet, and includes very low-level diagnostic data. This level should only be used in a development environment. When set to this level, the log includes all events that the Verbose setting records.

使用管理中心設定診斷記錄Configure diagnostic logging by using Central Administration

您可以使用 SharePoint 管理中心網站來設定診斷記錄。You can use the SharePoint Central Administration website to configure diagnostic logging.

使用管理中心設定診斷記錄To configure diagnostic logging by using Central Administration

  1. 在管理中心首頁上,按一下 [監視]*In Central Administration, on the Home page, click *Monitoring.

  2. 在 [監視] 頁面上,按一下 [報告]**** 區段中的 [設定診斷記錄]*On the Monitoring page, in the *Reporting section, click Configure diagnostic logging.

  3. 在 [診斷記錄] 頁面的 [事件節流]**** 區段中,按照下列方式設定事件節流:On the Diagnostic Logging page, in the Event Throttling section, configure event throttling as follows:

    設定所有類別的事件節流:To configure event throttling for all categories:

  4. 選取 [所有類別]**** 核取方塊。Select the All Categories check box.

  5. 選取 [回報至事件記錄的最低緊急事件]**** 清單中的事件記錄檔層級。Select the event log level from the Least critical event to report to the event log list.

  6. 選取 [回報至追蹤記錄的最低緊急事件]**** 清單中的追蹤記錄層級。Select the trace log level from the Least critical event to report to the trace log list.

    設定一或多個類別的事件節流:To configure event throttling for one or more categories:

  7. 選取所需類別的核取方塊。Select the check boxes of the categories that you want.

  8. 選取 [回報至事件記錄的最低緊急事件]**** 清單中的事件記錄檔層級。Select the event log level from the Least critical event to report to the event log list.

  9. 選取 [回報至追蹤記錄的最低緊急事件]**** 清單中的追蹤記錄層級。Select the trace log level from the Least critical event to report to the trace log list.

    設定一或多個子類別的事件節流 (您可以展開一或多個類別,並選取任何子類別):To configure event throttling for one or more subcategories (you can expand one or more categories and select any subcategory):

  10. 按一下類別旁的加號 [(+)]**** 展開類別。Click the plus (+) next to the category to expand the category.

  11. 選取子類別的核取方塊。Select the check box of the subcategory.

  12. 選取 [回報至事件記錄的最低緊急事件]**** 清單中的事件記錄檔層級。Select the event log level from the Least critical event to report to the event log list.

  13. 選取 [回報至追蹤記錄的最低緊急事件]**** 清單中的追蹤記錄層級。Select the trace log level from the Least critical event to report to the trace log list.

    若要將所有類別的事件節流回復為預設設定:To return event throttling for all categories to default settings:

  14. 選取 [所有類別]**** 核取方塊。Select the All Categories check box.

  15. 選取 [回報至事件記錄的最低緊急事件]**** 清單中的 [重設為預設]*Select *Reset to default from the Least critical event to report to the event log list.

  16. 選取 [回報至追蹤記錄的最低緊急事件]**** 清單中的 [重設為預設]*Select *Reset to default from the Least critical event to report to the trace log list.

  17. 在 [防止事件記錄檔濫記]**** 區段中,選取 [啟用防止事件記錄檔濫記]**** 核取方塊。In the Event Log Flood Protection section, select the Enable Event Log Flood Protection check box.

  18. 在 [追蹤記錄]**** 區段的 [路徑]**** 方塊中,輸入要寫入記錄的資料夾路徑。In the Trace Log section, in the Path box, type the path of the folder to which you want logs to be written.

  19. 在 [記錄檔儲存天數]**** 方塊中,輸入要將記錄保留的天數 (1 到 366)。此時間過後,將會自動刪除記錄。In the Number of days to store log files box, type the number of days (1-366) that you want logs to be kept. After this time, logs will automatically be deleted.

  20. 若要限制記錄檔可使用的磁碟空間,請選取 [限制追蹤記錄檔磁碟空間使用情況]**** 核取方塊,然後輸入要限制記錄檔的磁碟大小 (以 GB 為單位)。當記錄檔達到此值時,將會自動刪除較舊的記錄。To restrict the disk space that logs can use, select the Restrict Trace Log disk space usage check box, and then type the number gigabytes (GB) you want to restrict log files to. When logs reach this value, older logs will automatically be deleted.

  21. 在 [診斷記錄] 頁面上進行所需變更後,請按一下 [確定]*After you have made the changes that you want on the Diagnostic Logging page, click *OK.

使用 Windows PowerShell 設定診斷記錄Configure diagnostic logging by using Windows PowerShell

您可以使用 PowerShell 來設定診斷記錄。You can use PowerShell to configure diagnostic logging.

使用 Windows PowerShell 設定診斷記錄To configure diagnostic logging by using Windows PowerShell

  1. 確認您具備下列成員身分:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 授與使用 PowerShell Cmdlet 的權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use PowerShell cmdlets.

      注意

      如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  2. 從 SharePoint 管理命令介面,變更伺服器寫入記錄的磁碟。From the SharePoint Management Shell, change the drive to which the server writes logs.

  3. 在 PowerShell 命令提示字元中,輸入下列命令:At the PowerShell command prompt, type the following command:

    Set-SPDiagnosticConfig -LogLocation D:\DiagnosticLogs
    
  4. 若要限制記錄檔磁碟空間使用量,請在 PowerShell 命令提示字元處,輸入下列命令:To restrict log disk space usage, at the PowerShell command prompt, type the following command:

    Set-SPDiagnosticConfig -LogMaxDiskSpaceUsageEnabled
    

    或要指定記錄檔的磁碟空間上限:Or assign the maximum disk space for logs:

    Set-SPDiagnosticConfig -LogDiskSpaceUsageGB 500
    
  5. 若要檢視目前記錄層級,請在 PowerShell 命令提示字元處,輸入下列命令:To view the current logging level, at the PowerShell command prompt, type the following command:

    Get-SPLogLevel
    
  6. 若要變更記錄層級,請在 PowerShell 命令提示字元處,輸入下列命令:To change the logging level, at the PowerShell command prompt, type the following command:

    Set-SPLogLevel -TraceSeverity Monitorable
    

    若要將所有類別重新設定為預設層級,請在 PowerShell 命令提示字元處,輸入下列命令 ,然後按 ENTER :To set all categories back to default levels, at the PowerShell command prompt, type the following command, and then press ENTER:

    Clear-SPLogLevel
    
  7. 若要啟用事件記錄檔湧入保護,請在 PowerShell 命令提示字元處,輸入下列命令:To enable event log flooding protection, at the PowerShell command prompt, type the following command:

    Set-SPDiagnosticConfig -EventLogFloodProtectionEnabled
    

如需詳細資訊,請參閱 Set-SPDiagnosticConfigSet-SPLogLevelGet-SPLogLevelFor more information, see Set-SPDiagnosticConfig, Set-SPLogLevel and Get-SPLogLevel.

另請參閱See also

概念Concepts

SharePoint Server 2016 監視概觀Overview of monitoring in SharePoint Server