We've added support for the Log4net appender. This allows you to leverage your current investment in log4net, but leverage the power and flexibility that comes with the ReflectInsight viewer. You can view your log4net messages in realtime, in a rich viewer that allows you to filter out and search for what really matters to you.

The log4net extension supports Log4net v1.2.11.0. However if you need to support an older version, then you will need to download the ReflectInsight Logging Extensions Library from CodePlex. You can then reference and rebuild the extension against a specific release of the log4net dll. (Note: if you use the Nuget Package, the update to the latest version of log4net will be automatic).

Log4net Configuration

1. Download and install the ReflectInsight Viewer. You will need this installed to view your messages from the ReflectInsight Logging Extensions.


2. Download the ReflectInsight Extension Binaries or Source and rebuild if necessary. Alternatively you can use the NuGet package. See below for details on the NuGet package.

NOTE: If you have added the Log4net Extension from the NuGet gallery, then you can skip step #3 as it's already done for you.

3. Once you have the ReflectInsight Extensions, go to your project in Visual Studio and add a reference to:
  • ReflectSoftware.Insight.dll
  • ReflectSoftware.Insight.Extensions.Log4net.dll.
4. The next step is to configure your app or web configuration file and incorporate the ReflectInsight appender. If you don't already have an App.config or Web.config, add it. Then open the configuration file and add a new ConfigSection as shown here:

    <section name="insightSettings" type="ReflectSoftware.Insight.ConfigurationHandler,ReflectSoftware.Insight" />
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
5. Now you will need to add the InsightSettings section. You can get started with the following simple configuration:

      <configChange enabled="true"/>      
      <propagateException enabled="false"/>      
      <exceptionEventTracker time="20"/>
      <debugMessageProcess enabled="true" />

    <listenerGroups active="Debug">
      <group name="Debug" enabled="true" maskIdentities="false">
          <destination name="Viewer" enabled="true" filter="" details="Viewer"/>
      <instance name="log4netInstance1" category="Log4net1" />
6. Now you need to configure your log4net configuration with a reference to the ReflectInsight Appender. Update your log4net section with the following:

  <log4net debug="false">
    <appender name="MyLogAppender1" type="ReflectSoftware.Insight.Extensions.Log4net.LogAppender, ReflectSoftware.Insight.Extensions.Log4net">
      <param name="InstanceName" value="log4netInstance1" />
      <param name="DisplayLevel" value="true"/>
      <param name="DisplayLocation" value="true"/>

      <appender-ref ref="MyLogAppender1" />
7. Next go to your code file and the following for the log4net configuration (based on your log4net configuration being inside the app or web configuration file):
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using log4net;

// log4net stuff
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
7. Alternatively you can look at the configuration files that are part of the sample application.

8. That's it, you're done!

NuGet Package

We've created a NuGet package for our Log4net extension. You can find it over on Nuget.

To install ReflectSoftware.Insight.Extensions.Log4net extension, run the following command in the Package Manager Console.


Last edited Jul 16, 2013 at 10:03 PM by RSDeveloper, version 30