Copied to clipboard

Flag this post as spam?

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

  • Paul Blair 466 posts 731 karma points
    Feb 14, 2013 @ 04:59
    Paul Blair

    What is the correct best way for logging custom errors


    In the past I would do something like:


    which is not getting reported as obsolete and that I should use LogHelper

    So I now have

    LogHelper.Error<????>(errorMessage, exception)

    What should I be using as the type? And is this the recomended way for logging errors?



  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Feb 14, 2013 @ 13:05
    Jeroen Breuer

    Maybe check the Umbraco source to see how the LogHelper is used there?


  • Joao Pinto 24 posts 64 karma points
    Mar 01, 2013 @ 14:47
    Joao Pinto

    "The friendliest CMS community on the planet" :)

    Umbraco logging uses log4net, the TYPE should be the type of the object / class you are loggin, usually is used in this way:

    //You can specificy the class your are logging
    LogHelper.Error(typeof(MyClass), "msg", e);
    //Otherwise, you can use this code, that gets type automatically
    LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "msg", e);
  • Paul Blair 466 posts 731 karma points
    Mar 03, 2013 @ 22:00
    Paul Blair

    Hi Joao,

    Thanks for your help. I'm doing my logging within a Razor script so I was unsure what class was being logged. The full script I am testing is:

            client.EnableSsl = true;
            <p><strong>Your contact request has been sent. Someone will be in contact shortly</strong></p>
        catch (Exception ex)
            //LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Error creating or sending contact mail", ex.InnerException);
            umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Error, -1, string.Format("Error creating or sending contact mail: {0}", ex.InnerException));
            <p>Error: An error has occured sending your contact details. Please contact us directly using the phone or email listed above.</p>

    Even the old way of doing things is not recording an entry in the umbracoLog table so I'm wondering if there is an issue with v6.



  • Joao Pinto 24 posts 64 karma points
    Mar 04, 2013 @ 09:20
    Joao Pinto

    Hi Paul,

    currently I haven't tried the old api for logging on Umbraco V6, but I've used the new one and it works properly.

    So I suggest you to just change your code to use the new API, this simple code will work:

    LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "msg", ex);
  • Peter Duncanson 430 posts 1360 karma points c-trib
    May 22, 2013 @ 12:36
    Peter Duncanson

    @Joao, v6 now logs using log4net so take a look in /App_data/logs/ for your log entries and not the DB table. Hope that helps.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jun 19, 2013 @ 10:43
    Jeavon Leopold

    Really useful post thanks! I would add that to use the v6 log4net LogHelper you need to reference Umbraco.Core.Logging

    e.g in a Razor script:

    @using Umbraco.Core.Logging;
    LogHelper.Info(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Message"); 
  • Adrian 38 posts 117 karma points
    Jul 09, 2014 @ 11:40

    Much less typing!

    @using Umbraco.Core.Logging;
        LogHelper.Info(this.GetType(), "Message"); 
  • Steven Harland 78 posts 518 karma points c-trib
    Jul 15, 2014 @ 10:54
    Steven Harland

    Darren Ferguson has a great blog post on custom logging here.

    Maybe not exactly what you need but certainly useful nonetheless.

  • Michael Falk 37 posts 59 karma points
    Jan 26, 2015 @ 08:15
    Michael Falk

    OK, answering myself, addding

    using Umbraco.Core.Logging;

    then you can call:


     UPS, this was an answer to:

Please Sign in or register to post replies

Write your reply to: