Using Loupe 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 Loupe 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 Loupe with full fidelity and high performance. 

If you’re already using Log4Net, want one of its advanced capabilities not supported by Loupe, 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 Loupe Appender for Log4Net is provided in several ways - you can get it as part of the Loupe Agent for Log4Net from NuGet or just include the source code (it’s a single class) from the open source project on GitHub.  Once you’ve gotten the Loupe 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 Loupe! You can continue to use your existing logging targets in parallel without fear, which is particularly great if you’re trying out Loupe and don’t want to get in the way of your current processes.

For more information:

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

Rock solid centralized logging

Unlimited applications, unlimited errors, scalable from solo startup to enterprise.