Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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
  • 2
  • 2
LVL 83

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 : http://www.alteridem.net/2008/01/10/writing-an-appender-for-log4net/

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 83

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


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
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…
Suggested Courses

578 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