Developer forum

Forum » Development » Capture Custom Module errors

Capture Custom Module errors

Kevin O''Driscoll
Reply

Internally we have implemented error capture logging with Log4.net to capture application errors at data level, also web services etc

we have also added to Global.asax
all works good until we get to an error thrown in a DW custom module which gets handled by DW and bypasses Log4.net
Question is how to handle this type of error and log it to Log4.net

"An error occured while attaching module(Dynamicweb.Frontend.Content)"

--The error.....--

 


Replies

 
Kevin O''Driscoll
Reply
 
Nicolai Høeg Pedersen
Reply

Hi Kevin

There is no workaround for that currently.

Only idea is to check the entire ouput using a notification subscriber and then log if the output contains the error code.

Nicolai

 
Mikkel Ricky
Reply

A couple of suggestions:

  1. Make sure that your custom module does not generate any exceptions
  2. If it does, catch them and log using Log4.net. You could add a huge try-catch block around everything inside your custom GetContent method to catch any exceptions thrown.

Best regards,
Mikkel

 
Kevin O''Driscoll
Reply

Hi guys thanks for this was thinking a big try catch but would prefer a more global approach so maybe notification subscriber (page  or paragraph?) I noticed subscribers on paragraph slows the page load down a lot if many paragraphs. Is there a similar notification subscriber just for Custom Modules?

 
Nicolai Høeg Pedersen
Reply

Hi Kevin

A notification subscriber it self is not slow. The page.loaded notification is only run once on each pageview regardless of the number of the paragraphs.

If subscribers are slow it usually is because of the code inside the subscriber. You can add a debug=true to your page, and then you can see how many times a notification subscriber is called and how long it takes to execute.

There is no custom modules only notification subscriber.

Nicolai

 
Kevin O''Driscoll
Reply

Hi Nicolai and Mikkel. Interestingly our client has come up with a suggestion what do you think?:

namespace DwCustomModules.CustomModules
{
    public class ContentModuleBase : ContentModule
    {
        /// <summary>
        /// Over-Ride and Seal to prevent over-rides from replacing this method
        /// </summary>
        /// <returns></returns>
        public sealed override string GetContent()
        {
            try
            {
                return GetContentWithExceptionHandling();
            }
            catch(Exception ex)
            {
                try
                {
                    string errorMessage = string.Format("Unhandled Exception, Build: {0}, URL: {1}",
                        Assembly.GetExecutingAssembly().GetName().Version.ToString(),
                        Request.Url);

                    // Log a fatal error
                    ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                    log.Fatal(errorMessage, ex);
                }
                catch { ; } // For the time being ignore errors that occur during logging

                Response.Redirect(SearchEngineFriendlyURLs.GetFriendlyUrl(Config.Instance.DwErrorPageId), true);

                return string.Empty;
            }
        }

        /// <summary>
        /// Get Content With Exception Handling
        /// </summary>
        /// <returns></returns>
        public virtual string GetContentWithExceptionHandling()
        {
            return string.Empty;
        }
    }
}

and in our module:

[AddInName("CentreSearch")]
    public class Frontend : ContentModuleBase
    {
        public override string GetContentWithExceptionHandling()
        {
            // Set our Template
            Dynamicweb.Rendering.Template template = new Dynamicweb.Rendering.Template("CentreSearch/CentreSearch.htm");

            bla.......

         }

}

 

 

 
Mikkel Ricky
Reply

It's a nice solution, but I still think that the module itself, i.e. in GetContent, should handle any exceptions and take appropriate actions.

 

You must be logged in to post in the forum