Third Party Integration - Using Log4Net with Loupe
In This Topic
Loupe was designed to be the best way to process and view Log4Net data available.
- Log4Net event levels map to Loupe Log Message Severity. There are extra levels in Log4Net however the structure is maintained and all values are mapped to sensible Loupe values by default.
- Log4Net Loggers are carried over as Loupe Log Category Names. The hierarchal nature of loggers is maintained.
- Log4Net LocationInfo is augmented and stored in Loupe to provide the class & method where each log message originated and, if available, the file name and line number.
This agent is open source and hosted on GitHub. If you'd like to see it do something more/better/different or just curious how it works you can get the entire source code and even give the team a pull request or just log an issue.
How the Loupe Agent works with Log4Net
Loupe interfaces with Log4Net through the Loupe Agent for Log4Net. This allows it to work beside existing Appenders to allow you to try Loupe in parallel with your existing log storage techniques. Because Log4Net is available as source code and through a large number of binary distributions the Loupe Appender isn't compiled into the Loupe Agent. Instead, it is provided in source code and as an assembly compiled against the latest release of Log4Net available at the time of final testing of this release. You can include the Appender source code in your own library, or compile it as is, referencing the Log4Net version you are distributing.
Using the Loupe Appender for Log4Net
If you are using the latest official release from NuGet or the Apache Log4Net Distribution then can use the Loupe Agent for Log4Net (Gibraltar.Agent.Log4Net.dll) which is published on NuGet. When you add this NuGet package the Loupe Agent will automatically be added as well. Once you've added the Loupe Appender for Log4Net to your project you just need to connect it with Log4Net in your Log4Net configuration. For more information, see below.
Compiling your own Loupe Appender for Log4Net
If you are using a different release of Log4Net, including compiling your own copy from the original source code then you will need to
compile your own Loupe Appender. This is because the Loupe Appender for Log4Net is strongly named and therefore bound to a strongly named version of Log4Net. The complete source code for the Appender is on
GitHub. Just add this class to your project, add a reference to the Loupe Agent, and recompile. Once you've added the Loupe Appender for Log4Net to your project you just need to connect it with Log4Net in your Log4Net configuration. For more information, see below.
Configuring Log4Net to use the Loupe Appender
To attach the Loupe Appender to Log4Net and route messages to it you need to modify your application configuration file. A minimal example is shown below:
Example Title |
Copy Code
|
<?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" >
<param name="EndSessionOnAppenderClose" value="false" /> <!-- This is optional; it is false by default -->
</appender>
<root>
<level value="ALL" />
<appender-ref ref="GibraltarAppender" />
</root>
</log4net>
</configuration>
|
If you compile the Loupe Appender source code into another assembly, you will need to change the type information above to reflect the correct class name and assembly that you want your application to use. The example above uses the Loupe Appender for Log4Net assembly.
For complete information on how to configure Log4Net to work with appenders, consult the Log4Net documentation.
The source code provided for the Loupe Appender for Log4Net is freely redistributable and modifiable. Under the
Apache License used for Log4Net this is not considered a derivative work because it only uses interfaces from Log4Net and is entirely separate from the Loupe Agent.
See Also