1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Overriding Health Monitoring Provider to write events to DB

Overriding Health Monitoring Provider to write events to DB

4 posts, 0 answered
  1. James Reategui
    James Reategui avatar
    22 posts
    Registered:
    14 Oct 2008
    17 Feb 2009
    Link to this post

    Hey guys,

    It doesn't look like there is a built in way to write errors to the database instead of to a text file. 

    So, I figure the best way to achieve this is to make my own class that inherits from Telerik.Utilities.TextFileWebEventProvider and override the ProcessEvent method. Then, simply in web.config change the "Simple Web Event Provider" to my own.

    Is this the recommended path to follow? If so, is there any source code from that Utilities.TextFileWebEventProvider class that could be provided to help me in my quest?

    Thank you.

    This is what I have so far btw:

    public class CustomToilet : Telerik.Utilities.TextFileWebEventProvider  
    {  
        public override void ProcessEvent(System.Web.Management.WebBaseEvent raisedEvent)  
        {  
              // TODO: make it get raised event nicely and put into DB
        }  

  2. Parvan
    Parvan avatar
    151 posts
    Registered:
    24 Sep 2012
    18 Feb 2009
    Link to this post
    Hi James,

    Thank you for contacting us.

    Yes - you are right. It is possible to implement your custom Provider.
    HealthMonitoring is part from the ASP.Net and Sitefinity uses it. To change logging, you need to use the ASP.Net mechanism for healthMonitoring.
    Here is a sample on how to implement the provider you need - http://msdn.microsoft.com/en-us/library/system.web.management.webeventprovider(VS.80).aspx. You need to implement its methods, and configure it into the web.config only. 

    There is an ASP.Net provider for database logging as well - System.Web.Management.SqlWebEventProvider.
    The events will be saved in the table aspnet_WebEvents_Event in your database

    1. You need to setup the aspnet_WebEvents_Event table. Please use the aspnet_regsql.exe from the Visual Studio.NET 2008(2005) command prompt, and provide the connection to your website database.

    2. You need to change the configuration in your web.config:
     <healthMonitoring enabled="true" heartbeatInterval="0" > 
    ...  
    <providers> 
        <remove name="SqlWebEventProvider"/>  
    ...  
        <add name="SqlWebEventProvider" connectionStringName="Sitefinity" maxEventDetailsLength="1073741823" buffer="false" bufferMode="Notification" type="System.Web.Management.SqlWebEventProvider,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"/>  
    </providers>   
    <rules> 
       <add name="SitefinityEventHandler"   
        eventName="Simple Web Request Event"   
        provider="SqlWebEventProvider"   
        minInterval="00:00:00" minInstances="1" maxLimit="Infinite"/>  
    ...  
    </rules> 
    </healthMonitoring> 

    Hope this information will help you.

    Best wishes,
    Parvan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. James Reategui
    James Reategui avatar
    22 posts
    Registered:
    14 Oct 2008
    20 Feb 2009
    Link to this post
    Thanks for the help. I was able to build my own Health provider and make it work.
    Couple notes I learned that might help other people:

    - If you want to place your custom HealthMonitoring class in the same project as sitefinity, you must first convert your SF website project into a web application. This is because the in the website mode the healthmonitoring is loaded prior to assemblies compiling. Here is how to convert: http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-bmdmam.aspx

    - The error that comes in is of type Telerik.Utilities.SimpleWebRequestEvent so be sure to cast the WebBaseEvent in the ProcessEvent method when using it. ie:
    1 public class MyWebEventProvider : System.Web.Management.WebEventProvider 
    2
    3     ....     
    4      
    5     public override void ProcessEvent(WebBaseEvent raisedEvent) 
    6     { 
    7         Telerik.Utilities.SimpleWebRequestEvent eventRaised = (Telerik.Utilities.SimpleWebRequestEvent eventRaised)raisedEvent; 
    8         // save error via web service to database         
    9         WebService.Health ws = new Webservice.Health; 
    10         ws.SaveErrorToDb(eventRaised); 
    11     } 
    12  
    13

    - If you dont want to convert your project to a web application, you must create your class in a seperate class project and add a reference to the compiled dll in the SF project.

  4. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    23 Feb 2009
    Link to this post
    Hello James,

    Thank you for providing these details. We have updated your Telerik account for that!
    We are glad you managed to achieve your task.

    Sincerely yours,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
4 posts, 0 answered