Log4Net custom Appender not being fired.

Posted on 2016-10-14
Last Modified: 2016-11-26
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.
Question by:townsma
  • 2
  • 2
LVL 82

Accepted Solution

leakim971 earned 500 total points
ID: 41883679
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 :

Author Comment

ID: 41884427
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.
LVL 82

Expert Comment

ID: 41884593
it's just to be sure it work fine like that...

Author Comment

ID: 41902736
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.

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question