JavaScript Editor jscript editor     Web designer 

Main Page

The example in the topic Custom ASP.NET Health Monitoring Provider Example illustrates how to create a custom provider that processes ASP.NET health events. The code example shows how to derive from the BufferedWebEventProvider class to create a custom provider that writes the event information to a local file.

The example is deliberately simple. The intent is to give you full control of a custom provider's basic mechanisms. In a real-world scenario, you could use the example code as a preliminary probe into the behavior of an application to help you understand the information provided by ASP.NET health monitoring.

The example provider demonstrates the following features:

Running the example requires the following:

To build the custom event provider

  • Compile the custom event provider as a library and place the library in your ASP.NET application's Bin directory, or strongly name the assembly and place it in the global assembly cache (GAC).

    The following command example shows how you can compile the example using the command-line compiler.

    Visual BasicВ CopyCode imageCopy Code
    vbc /out:<example_name>.dll /t:library <example_name>.vb /r:System.Web.dll /r:System.Configuration.dll /r:<required namespace>

    C#В CopyCode imageCopy Code
    csc /out:<example_name>.dll /t:library <example_name>.cs /r:System.Web.dll /r:System.Configuration.dll  /r:<required namespace>

    If you cannot execute the compiler command, you must add the .NET Framework installation path to the Windows PATH variable before running the command. In Windows, right-click My Computer, click Properties, click the Advanced tab, and then click the Environment Variables button. In the System variables list, double-click the Path variable. In the Variable value text box, add a semicolon (;) to the end of the existing values in the text box, and then type the path of your .NET Framework installation. The .NET Framework is usually installed in the Windows installation folder at \Microsoft.NET\Framework\versionNumber.

To configure the application to use the example

  1. If your application already contains a file named Web.config in the root folder, open it. Otherwise, create a text file named Web.config and add the following text.

    В CopyCode imageCopy Code
    <?xml version="1.0"?>
    <configuration xmlns="">
  2. Inside the system.web tags, add the following healthMonitoring element.

    В CopyCode imageCopy Code
        heartBeatInterval="0" enabled="true">
        <add name="Custom Notification"
        <add name="SampleEventProvider" type="Samples.AspNet.Management.SampleBufferedEventProvider" 
        bufferMode="Custom Notification" />
        <add name="Custom"
          minInterval="00:00:00" />
        <add name="Custom Event Provider"
          eventName="All Events"
          profile="Custom" />

    The settings in the healthMonitoring element use a providers element to add the custom provider and specify a profiles element that (in this case) protects the server by limiting the number of times the event can be raised. The example also includes a rules element to associate an event with the profile and the provider.

    The type attribute can list just the class name as it does in the previous code example, or it can list a fully qualified type, as in the following example:

    В CopyCode imageCopy Code

    The fully qualified type is required only if the class has been installed in the GAC or in the Bin directory.

To test the custom Web event

  1. In your browser, request any page from the Web application.

    Running any page in the application raises the custom event.

  2. To view your custom event data, open the log file specified by the logFilePath variable in the code.

See Also


healthMonitoring Element (ASP.NET Settings Schema)


Custom ASP.NET Health Monitoring Provider Example

Other Resources

ASP.NET Health Monitoring
ASP.NET Web Applications

JavaScript Editor jscript editor     Web designer