共用方式為


WebRequestInformation.FormatToString(WebEventFormatter) 方法

定義

格式化 Web 要求資訊。

public:
 void FormatToString(System::Web::Management::WebEventFormatter ^ formatter);
public void FormatToString (System.Web.Management.WebEventFormatter formatter);
member this.FormatToString : System.Web.Management.WebEventFormatter -> unit
Public Sub FormatToString (formatter As WebEventFormatter)

參數

formatter
WebEventFormatter

包含用來將 Web 健康情況事件資訊格式化之定位和縮排設定的 WebEventFormatter

範例

下列程式碼範例示範如何格式化自訂資訊。


// Formats Web request event information.
public override void FormatCustomEventDetails(
 WebEventFormatter formatter)
{

    // Add custom data.

    formatter.AppendLine("");
    formatter.AppendLine(
        "Custom Request Information:");

    formatter.IndentationLevel += 1;

    // Display the request information obtained 
    // using the WebRequestInformation object.
    formatter.AppendLine(GetRequestPath());
    formatter.AppendLine(GetRequestUrl());
    formatter.AppendLine(GetRequestUserHostAdddress());
    formatter.AppendLine(GetRequestPrincipal());

    formatter.IndentationLevel -= 1;

    formatter.AppendLine(eventInfo.ToString());
}
' Formats Web request event information.
 Public Overrides Sub FormatCustomEventDetails( _
 ByVal formatter As WebEventFormatter)

     ' Add custom data.
     formatter.AppendLine("")
     formatter.AppendLine("Custom Request Information:")

     formatter.IndentationLevel += 1

     ' Display the request information obtained 
     ' using the WebRequestInformation object.
     formatter.AppendLine(GetRequestPath())
     formatter.AppendLine(GetRequestUrl())
     formatter.AppendLine(GetRequestUserHostAdddress())
     formatter.AppendLine(GetRequestPrincipal())
     formatter.IndentationLevel -= 1

     formatter.AppendLine(eventInfo.ToString())
 End Sub

備註

方法 FormatToString 會為事件資訊提供統一格式,如果必須記錄事件資料,稍後再向使用者呈現,這非常有用。 當提供者叫用其中 ToString 一個方法時,會在內部呼叫它。

適用於