Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Log4Net custom Appender not being fired.

Posted on 2016-10-14
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 82

Accepted Solution

leakim971 earned 2000 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The well known Cerber ransomware continues to spread this summer through spear phishing email campaigns targeting enterprises. Learn how it easily bypasses traditional defenses - and what you can do to protect your data.
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…

722 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