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

适用于