• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

Log4Net custom Appender not being fired.

I have created a simple log4net custom appender, code below, to access a JSON Web Service.  Everything seems to initialize correctly, but the Append method is never called.  Can someone please tell me what I am doing wrong.  Thanks

public class RMAppender : AppenderSkeleton
        protected override void Append(LoggingEvent loggingEvent)
            var url = ConfigurationManager.AppSettings["EventLogServer"];
            if (string.IsNullOrEmpty(url)) return;

            var client = new JsonServiceClient(url);

            var data = loggingEvent.MessageObject as IList<string>;

            if (data != null)
                foreach (var s in data)
                    // Do something with each string

            var log = new LogEntry
                CurrentAppDomain = loggingEvent.Domain,
                Logger = loggingEvent.LoggerName,
                Date = DateTime.Now

            var response = client.Post<LogEntry>(log);

Open in new window

This is configured in code using:

private static void ConfigureLog()
            var root = ((Hierarchy)LogManager.GetRepository()).Root;

#if (DEBUG)

            var append = new RMAppender();
            append.Threshold = Level.All;

            root.Repository.Configured = true;

Open in new window

I have used this same method for adding other appenders including EventLog, SMTP etc.  and they all work.  It is only the custom one that Append is never called.

I checked root, and following the above, the appender is listed under root.Appenders, and appears to be configured the same way as all the other appenders.

This has got me really stumped.  I am sure I am missing something, but I cannot see what.
  • 2
  • 2
1 Solution
could you try tho config like this (you've to change yournamespace) :

<?xml version="1.0" encoding="utf-8" ?>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
        <appender name="MessageBoxAppender" type="yournamespace.log4net.RMAppender, log4netExtensions">
            <layout type="log4net.Layout.PatternLayout">
                <ConversionPattern value="%m" />
            <level value="ERROR"/>
            <appender-ref ref="RMAppender" />

Open in new window

check this page : http://www.alteridem.net/2008/01/10/writing-an-appender-for-log4net/
townsmaAuthor Commented:
So you are saying is that we can only use a custom appender if we use an external config file?  Because all out log4net config is hard-coded into the application, as per my sample above.
it's just to be sure it work fine like that...
townsmaAuthor Commented:
My apologies for the delay in getting back to you. I did look at the advice above, and tried to incorporate it, however, because the remainder of the class uses hard coded settings, it was causing confusion between the config file and the hard coded settings.  

At the same time someone one suggestion I take a look at a different, paid for, product. Kellerman .Net Logging.   This seemed to have all we required, and at a reasonable price.  It was very easy to plug in, as many of the calls are almost identical, and it worked first time with my Custom Appender.  So we have decided to abandon log4net, and stick with .Net Logging.

So many thanks for your help.  If I have time in the future I will make a new class from scratch that just uses config files to test it out, if it works I will post back here for others.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now