2
votes

Let's say I have the following appender references configuration in my .log4net.config file:

<root>
  <level value="ALL"/>
  <appender-ref ref="ColoredConsoleAppender" />
  <appender-ref ref="EventLogAppender"/>
  <appender-ref ref="RollingLogFileAppender" />
  <appender-ref ref="MyCustomAppender" />
</root>

Does log4net invoke these appenders serially on a single thread (i.e. the same thread that the calling application used to call the ILog.* method). And if so, what order does it invoke each appender? Is it done in the same order as they are defined in the <root> element?

2

2 Answers

2
votes

According to this link (in the section on Custom Appenders: Adding Destinations), log4net executes the Appenders in the order in which they appear in the config file. Also, the Appenders are executed synchronously. I don't know if the author is a log4net expert or not, but the article reads well enough.

0
votes

While I couldn't find any independent confirmation of what was stated in link,http://www.devx.com/dotnet/Article/32096/1954, either at the log4net site or through further googling I have changed the order of my appenders in configuration file as shown below based on the article.

Maybe the root element is the critical element to order by I changed order of appender elements in log4net element as well

My reasoning is that in a critical failure scenario logging to windows event log is going to have more success than writing to file (and could be argued it is more important info?)

<log4net threshold="ALL">
    <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
        <!-- Make stuff go here -->
    </appender>
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
        <!-- Make stuff go here -->
    </appender>
    <root>
      <appender-ref ref="EventLogAppender" />
      <appender-ref ref="RollingFileAppender" />
    </root>
</log4net>