WebApplicationInformation.FormatToString(WebEventFormatter) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
格式化應用程式資訊。
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)
{
base.FormatCustomEventDetails(formatter);
// Add custom data.
formatter.AppendLine("");
formatter.AppendLine(
"Custom Application Information:");
formatter.IndentationLevel += 1;
// Display the application information.
formatter.AppendLine(GetApplicationDomain());
formatter.AppendLine(GetApplicationPath());
formatter.AppendLine(GetApplicationVirtualPath());
formatter.AppendLine(GetApplicationMachineName());
formatter.AppendLine(GetApplicationTrustLevel());
formatter.IndentationLevel -= 1;
formatter.AppendLine(eventInfo.ToString());
}
'Formats Web request event information.
Public Overrides Sub FormatCustomEventDetails( _
_
ByVal formatter As WebEventFormatter)
MyBase.FormatCustomEventDetails(formatter)
' Add custom data.
formatter.AppendLine( _
"Custom Application Information:")
formatter.IndentationLevel += 1
' Display the application information.
formatter.AppendLine(GetApplicationDomain())
formatter.AppendLine(GetApplicationPath())
formatter.AppendLine(GetApplicationVirtualPath())
formatter.AppendLine(GetApplicationMachineName())
formatter.AppendLine(GetApplicationTrustLevel())
formatter.IndentationLevel -= 1
formatter.AppendLine(eventInfo.ToString())
End Sub
End Class
備註
方法 FormatToString 會為事件資訊提供統一格式,如果必須記錄事件資料,稍後再向使用者呈現,這非常有用。 當提供者叫用其中 ToString 一個方法時,會在內部呼叫它。
注意
格式化自訂事件資訊以顯示時,請覆寫 FormatToString 方法,而不是 ToString 方法。 這可避免覆寫或竄改敏感性系統資訊。