Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Umbraco 137 posts 294 karma points
    Aug 29, 2013 @ 12:02
    Umbraco
    0

    Is there a way to get exception logging for macros when umbracoDebugMode=false?

    umbracoDebugMode is false in web.config (and I can't change it), but enableLogging is true in umbracoSettings.config.

    Unfortunately, the exceptions thrown when rendering a macro do not get logged. I am using Umbraco 4.7.2.

    How can I see the exception for "Error loading MacroEngine script" errors?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 29, 2013 @ 21:50
    Jeavon Leopold
    101

    Hi Michiel,

    This is how I have done it in the past

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using umbraco.BusinessLogic
     @{
        try
        {
        //do stuff
        }
       catch (Exception e)
        {
            Log.Add(LogTypes.Error, Model.Id, string.Format("Razor exception caught: {0}", e.ToString()));
        }
    
    }
    

    The exceptions will be logged to the umbracoLog table. You can then view them directly in the db or use the FALM package.

    Of course you can also display the excepiton on the page if you want to, e.g.

       catch (Exception e)
        {
            <div style="color:red">@e.Message</div>
            Log.Add(LogTypes.Error, Model.Id, string.Format("Razor exception caught: {0}", e.ToString()));
        }
    

    Hope that helps you,

    Jeavon

  • Umbraco 137 posts 294 karma points
    Aug 30, 2013 @ 08:17
    Umbraco
    0

    Ok, so basically I have to write my own logging code, Umbraco does not log such exceptions at all?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 30, 2013 @ 11:10
    Jeavon Leopold
    0

    That's right, in v6 there is a new setting for how the macro engine handles exceptions and I think if it's set to throw then exceptions are logged automatically (I'm not 100% sure) but you probably don't want that on your production site anyway so best to log them yourself.

Please Sign in or register to post replies

Write your reply to:

Draft