You are here:

Using Gibraltar with Log4Net

Today’s Advent treat is how you can easily use Log4Net with Gibraltar

Log4Net is, hands down, the most popular logging framework for .NET outside of Trace logging that’s built into the framework itself.   When we were designing the Gibraltar logging API we looked first at the capabilities of Log4Net.  Because of this, while our API is notably different we designed it to make it easy to route messages from Log4Net into Gibraltar with full fidelity and high performance. 

If you’re already using Log4Net, want one of its advanced capabilities not supported by Gibraltar, or have a third party library you’re using that you want to capture data from you’ll want to take advantage of our Log4Net Appender.

The Gibraltar Appender for Log4Net is provided in several ways – you can get it as part of the Gibraltar Agent for Log4Net from NuGet or in the SDK directory once you’ve installed Gibraltar or just include the source code (it’s a single class) that is in the SDK directory.  Once you’ve gotten the Gibraltar Appender integrated you need to adjust your Log4Net configuration to add it.  Typically this is done by editing your application configuration file (e.g. app.config or web.config) like the following:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
  <log4net>
    <appender name="GibraltarAppender" type="Gibraltar.Agent.Log4Net.GibraltarAppender, Gibraltar.Agent.Log4Net" >
      <!-- This is optional; it is false by default -->
      <param name="EndSessionOnAppenderClose" value="false" />
    </appender>
    <root>
      <level value="ALL" />
      <appender-ref ref="GibraltarAppender" />
    </root>
  </log4net>
</configuration>

And that’s it – a small change to your Log4Net configuration file and you’re sending information to Gibraltar! You can continue to use your existing logging targets in parallel without fear, which is particularly great if you’re trying out Gibraltar and don’t want to get in the way of your current processes.

For more information:

You can use the Gibraltar Agent for Log4Net as part of a migration strategy to transition your logging to working with Gibraltar directly or as a long term approach to take advantage of other benefits Log4Net offers.

Is there something else we could do to make Gibraltar more valuable to you? Submit your killer idea to our contest! You’ll have a chance to win a fantastic prize and may just see your ideas in our next release!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

clear formSubmit