Copied to clipboard

Flag this post as spam?

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


  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Jul 17, 2013 @ 17:13
    Ismail Mayat
    0

    Log4net logging

    Guys,

    Probably one for the core team. I am doing some custom logging in my class using the umbraco logging api in v6 which logs out using log4net my code looks like

    LogHelper.Error<Exception>("Error writing to eloqua for email address " + record.EmailAddress, ex);

    I have as well the default file appender setup and email appender with a filter. So my log4net smtp appender looks like

      <appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">

        <to value="xxx" />

        <from value="xxx" />

        <subject value="Info graphic error" />

        <smtpHost value="localhost" />

        <bufferSize value="512" />

        <lossy value="true" />

        <evaluator type="log4net.Core.LevelEvaluator">

          <threshold value="ERROR"/>

        </evaluator>

        <layout type="log4net.Layout.PatternLayout">

          <conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline" />

        </layout>

        <filter type="log4net.Filter.LoggerMatchFilter">

          <loggerToMatch value="MyProject.BusinessLogic.Helpers.RazorHelper" />

        </filter>

        <filter type="log4net.Filter.DenyAllFilter" />

      </appender>

    I do not get an email when an error occurs. I go get message in log file. However one thing I noticed is that in the logfile there is no type for where occur occurred. So when you have umbraco errors in the log you have 

    ERROR Umbraco.Core.PluginManager

    ERROR umbraco.DataLayer.SqlHelper

    For my error you see ERROR System.Exception so I guess when logging is happening in the bowels of umbraco the logger is given type where as when we log its not? Is this why my filter misses the exception? Do i need to log directly using log4net like umbraco in the bowels does? That is assuming umbraco does it directly with log4net and not with an abstraction around log4net?

    Regards

     

    Ismail

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Jul 17, 2013 @ 17:28
    Ismail Mayat
    100

    So in answer to my own question. Im an idiot!!  So if log the error as

     LogHelper.Error(typeof(RazorHelper), "Error writing to eloqua for email address " + record.EmailAddress, webex);

    It all works woohoo!

    Regards

    Ismail

  • John Hildebrant 14 posts 35 karma points
    Aug 22, 2014 @ 16:52
    John Hildebrant
    0

    Is there documentation somewhere on how to use the logger in Umbraco?

  • Chris Wilson 100 posts 377 karma points
    Jan 12, 2015 @ 12:08
    Chris Wilson
    0

    I'm afraid not John, you get the same level of documentation as with most other features - nothing beyond the source code.

    When implementing my own custom logging I found the following blog post incredibly helpful: http://blog.darren-ferguson.com/2013/02/22/log4net-logging-from-your-custom-code-in-umbraco/

    Though as this was written in 2013, you should be aware that the Log.Error() approach has been superseded by the LogHelper.Error() implementation, the article is however incredibly helpful when setting up custom logs and specifying applicable namespaces for those logs to be written from.

Please Sign in or register to post replies

Write your reply to:

Draft