To convert your .NET application's existing use of the NLog logging framework to include Loupe you need:
If you reference the NLog.dll distributed with Loupe or the same version retrieved directly from the NLog Project site it then you may add this distribution's Gibraltar.Agent.NLog2.dll binary to your references rather than include the GibraltarTarget class in your project. You can also get this assembly from NuGet. This is the simplest way to use the Loupe NLog Target because we've already created a strong named assembly linked to the distribution of the Loupe Agent included in this release and NLog 2.
If you reference the distributed NLog.dll distributed with this release then you may add this distribution's Gibraltar.Agent.NLog2.dll binary to your references rather than include the GibraltarTarget class in your project. If you instead wish to rebuild Gibraltar.Agent.NLog2 from source code:
Loupe is intended as a top-level catch-all to collect all of your logging in one managed place so you can filter as needed dynamically during analysis. To do this, modify the extensions
, targets
, and rules
sections of your NLog configuration as follows:
<add assembly="Gibraltar.Agent.NLog2" />
<target name="Gibraltar" xsi:type="Gibraltar" />
type="Gibraltar"
--if not using explicit namespaces)<logger name="*" minlevel="Trace" writeTo="Gibraltar" />
If you find minlevel="Trace"
too voluminous for normal collection, the minlevel may be set at "Debug"
instead. Also, see the example App.config
file in the Gibraltar.Agent.NLog project, and consult the NLog configuration documentation as needed.
Example App.config for Integrating the GibraltarTarget with NLog |
Copy Code
|
---|---|
<?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> <add assembly="Gibraltar.Agent.NLog2" /> <!--Contains GibraltarTarget class marked as "Gibraltar" target type--> </extensions> <targets> <target name="Gibraltar" xsi:type="Gibraltar" /> <!--Define a named target using the "Gibraltar" target type--> </targets> <rules> <logger name="*" minlevel="Trace" writeTo="Gibraltar" /> <!--Send all logging to the "Gibraltar" named target--> </rules> </nlog> </configuration> |
In the above example no Loupe Agent configuration information was included. You can add in any necessary Loupe Agent configuration manually or via NuGet.
Make sure to log something to Loupe early in your application (e.g. before Application.Run) to load the Loupe Agent and initialize its automatic monitoring features. For example:
Example NLog Application Startup Message |
Copy Code
|
---|---|
mainLogger.LogInfo("Entering application.");
|
You can also take either of the approaches listed in Developer's Guide for WinForms - Ensuring the Loupe Agent gets Loaded.
Because NLog doesn't have any way of signaling to its logging targets that the log system is shutting down you should follow the instructions in Developer's Guide - .NET Framework - Ensuring Your Application Exits to ensure that your application exits. As an example, the following line placed just before the routine exit of your application will ensure it exits quickly:
Example Application Shutdown |
Copy Code
|
---|---|
Gibraltar.Agent.Log.EndSession("Application Exiting Normally");
|