Share via


WebProcessInformation Classe

Definizione

Fornisce informazioni sul processo di lavoro che ospita ASP.NET.

public ref class WebProcessInformation sealed
public sealed class WebProcessInformation
type WebProcessInformation = class
Public NotInheritable Class WebProcessInformation
Ereditarietà
WebProcessInformation

Esempio

L'esempio seguente è costituito da due parti. Il primo è un estratto di un file di configurazione che consente ASP.NET di usare un evento personalizzato che usa il WebProcessInformation tipo .

Il secondo illustra come implementare l'evento personalizzato.

Assicurarsi che l'evento personalizzato venga generato al momento corretto, ovvero quando verrà generato l'evento di integrità del sistema equivalente che sostituisce.

<healthMonitoring   
  enabled="true" heartBeatInterval="0">  

    <eventMappings>  
      <add    
        name="SampleProcessInformation"   
        type="SamplesAspNet.SampleWebProcessInformation, webprocessinformation, Version=1.0.1585.27289, Culture=neutral, PublicKeyToken=3648e5c763a8239f, processorArchitecture=MSIL"/>  
    </eventMappings>  

    <rules>  
      <add   
        name="Custom Process Information"  
        eventName="SampleProcessInformation"   
        provider="EventLogProvider"  
        profile="Default"/>  
    </rules>  

</healthMonitoring>  

Nell'esempio seguente viene illustrato come implementare un evento personalizzato che usa il WebProcessInformation tipo .


using System;
using System.Text;
using System.Web;
using System.Web.Management;

namespace SamplesAspNet
{
    // Implements a custom WebBaseEvent type that 
    // uses WebProcessInformation.
    public class SampleWebProcessInformation: 
        WebManagementEvent
    {
        private StringBuilder eventInfo;
        // Instantiate SampleWebProcessInformation.    
        public SampleWebProcessInformation(string msg, 
            object eventSource, int eventCode) : 
        base(msg, eventSource, eventCode)
        {
            // Perform custom initialization.
            eventInfo = new StringBuilder();
            eventInfo.Append(string.Format(
            "Event created at: {0}", 
            EventTime.ToString()));
        }   

        // Raises the event.
        public override void Raise()
        {
            // Perform custom processing. 
            eventInfo.Append(string.Format(
            "Event raised at: {0}", 
            EventTime.ToString()));

            // Raise the event.
            base.Raise();
        }

        public string GetAccountName()
        {
            // Get the name of the account.
            return (string.Format(
                "Account name: {0}", 
                ProcessInformation.AccountName));
        }

        public string GetProcessId()
        {
            // Get the process identifier.
            return (string.Format(
                "Process Id: {0}", 
                ProcessInformation.ProcessID.ToString()));
        }

        public string GetProcessName()
        {
            // Get the requests in execution.
            return (string.Format(
                "Process name: {0}", 
                ProcessInformation.ProcessName));
        }

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

            // Add custom data.
            formatter.AppendLine("Custom Process Information:");
            formatter.IndentationLevel += 1;

            // Display the process information.
            formatter.AppendLine(GetAccountName());
            formatter.AppendLine(GetProcessId());
            formatter.AppendLine(GetProcessName());
            formatter.IndentationLevel -= 1;
            formatter.AppendLine(eventInfo.ToString());
        }
    }
}
Imports System.Text
Imports System.Web
Imports System.Web.Management


' Implements a custom WebBaseEvent type that 
' uses WebProcessInformation.

Public Class SampleWebProcessInformation
   Inherits WebBaseEvent
   Private eventInfo As StringBuilder
    Private Shared processInformation _
    As WebProcessInformation
   
   ' Instantiate SampleWebProcessInformation.    
    Public Sub New(ByVal msg As String, _
    ByVal eventSource As Object, ByVal eventCode As Integer)
        MyBase.New(msg, eventSource, eventCode)
        ' Perform custom initialization.
        eventInfo = New StringBuilder
        eventInfo.Append(String.Format( _
        "Event created at: {0}", _
        EventTime.ToString()))

    End Sub
   
   ' Raises the event.
   Public Overrides Sub Raise()
      ' Perform custom processing. 
        eventInfo.Append(String.Format( _
        "Event raised at: {0}", _
        EventTime.ToString()))
      
      ' Raise the event.
      MyBase.Raise()
   End Sub
   
   Public Function GetAccountName() As String
      ' Get the name of the account.
        Return String.Format("Account name: {0}", _
        processInformation.AccountName)
   End Function 'GetAccountName
   
   Public Function GetProcessId() As String
      ' Get the process identifier.
        Return String.Format("Process Id: {0}", _
        processInformation.ProcessID.ToString())
   End Function 'GetProcessId
   
   Public Function GetProcessName() As String
      ' Get the requests in execution.
        Return String.Format("Process name: {0}", _
        ProcessInformation.ProcessName)
   End Function 'GetProcessName
   
    'Formats Web request event information.
    Public Overrides Sub FormatCustomEventDetails( _
    ByVal formatter _
    As System.Web.Management.WebEventFormatter)
        MyBase.FormatCustomEventDetails(formatter)
   
        ' Add custom data.
        formatter.AppendLine("")
        formatter.AppendLine( _
        "Custom Process Information:")
        formatter.IndentationLevel += 1

        ' Display the process information.
        formatter.AppendLine(GetAccountName())
        formatter.AppendLine(GetProcessId())
        formatter.AppendLine(GetProcessName())
        formatter.IndentationLevel -= 1
        formatter.AppendLine(eventInfo.ToString())
    End Sub

End Class

Commenti

ASP.NET monitoraggio dell'integrità consente al personale operativo e di produzione di gestire le applicazioni Web distribuite. Lo System.Web.Management spazio dei nomi contiene i tipi di evento di integrità responsabili della creazione del pacchetto dei dati sullo stato di integrità dell'applicazione e i tipi di provider responsabili dell'elaborazione di questi dati. Contiene anche tipi di supporto utili durante la gestione degli eventi di integrità.

Le istanze della WebProcessInformation classe contengono informazioni ottenute usando uno dei tipi derivati dal WebManagementEvent tipo .

L'applicazione deve disporre delle autorizzazioni appropriate per accedere alle informazioni protette fornite da questo tipo.

L'esempio seguente è un estratto del file di configurazione che è possibile usare per consentire a ASP.NET di registrare gli eventi di errore contenenti informazioni sul processo.

<healthMonitoring   
  enabled="true" heartBeatInterval="0">  

    <rules>  
     <add   
       name="All Errors Default"  
       eventName="All Errors"  
       provider="EventLogProvider"  
       profile="Default"  
       minInterval="00:01:00" />  
    </rules>  

</healthMonitoring>  

Nota

Nella maggior parte dei casi sarà possibile usare i tipi di monitoraggio dell'integrità ASP.NET implementati e sarà possibile controllare il sistema di monitoraggio dell'integrità specificando i valori nella healthMonitoring sezione di configurazione. È anche possibile derivare dai tipi di monitoraggio dell'integrità per creare provider ed eventi personalizzati. Per un esempio di creazione di una classe di evento personalizzata, vedere la sezione Esempio.

Proprietà

AccountName

Ottiene il nome account del processo di lavoro.

ProcessID

Ottiene l'identificatore di processo.

ProcessName

Ottiene il nome del processo.

Metodi

Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
FormatToString(WebEventFormatter)

Formatta le informazioni dell'applicazione.

GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetType()

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Si applica a

Vedi anche