Using Loupe with NLog

Today’s Advent treat is how you can easily use NLog with Loupe

Loupe has a built-in logging API that’s designed to cover a wide range of user scenarios, but sometimes you want to complement that with a third-party logging system like NLog.  This may be because you already have a deep investment in NLog or perhaps it has a feature that we don’t support yet.

The good news is that Loupe comes with an NLog Target, a small class that interfaces from NLog to an external logging system (like Loupe).  We provide this target via NuGet as well as in the SDK directory when you install Loupe.  It’s available both as an assembly and as source code so you have a lot of deployment options.

Once you’ve gotten the Loupe logging target for NLog you have to configure NLog to use it.  NLog can pull its configuration from the application configuration file (e.g. app.config or web.config) or from a separate configuration file.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
  </configSections>
  <!-- In an NLog.config file only this "nlog" section is needed as the root.  App.config also needs the rest. -->
  <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <extensions>
      <!--Contains GibraltarTarget class marked as "Gibraltar" target type-->
      <add assembly="Gibraltar.Agent.NLog2" />
    </extensions>
    <targets>
      <!--Define a named target using the "Gibraltar" target type-->
      <target name="Gibraltar" xsi:type="Gibraltar" />
    </targets>
    <rules>
      <!--Send all logging to the "Gibraltar" named target-->
      <logger name="*" minlevel="Trace" writeTo="Gibraltar" />
    </rules>
  </nlog>
</configuration>

And that’s it - a small change to your NLog 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:

We really like NLog - it’s a great, open source log system.  That’s one of the reasons we’ve made sure we have great support to let you capture all of that information along with everything else the Loupe Agent already captures.  You can use it 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 NLog offers.

Related Posts

Loupe 4.5 Released with New Log Viewer for Web

Rapidly diagnose each error in any .NET application with our new Web Log Viewer and Exception root cause analysis, new in Loupe 4.5. New integration with Azure Service Bus and Azure Search enables full Loupe functionality without any Virtual Servers in Azure. Read more

Cloudflare Vulnerability Does Not Affect Us

The recently reported Cloudflare vulnerability where fragments of secure, encrypted user data could be exposed to a third party does not affect Gibraltar Software even though we use Cloudflare because we only route static content through the Cloudflare proxy for acceleration. Read more

We're out of our Last Data Center

Back in January of 2016 we decided to completely transition out of our data centers and into the cloud. On Sunday we finally shut down the last cluster of our hardware. Read more for how we did it and whether we would do it all over again if we had... Read more

Rock solid centralized .NET logging

Unlimited applications, unlimited errors, starting at $25/month