Documentation - Log4Net HarvesterAppender
Integrating your application with Harvester is as easy as adding an additional appender to the Log4Net configuration section.
OutputDebugString Target
Recommended for Microsoft .NET 3.5 or earlier applications!
NLog's built in OutputDebugString target is a viable option to push debug messages to Harvester. The OutputDebugString target will work with Microsoft .NET 3.5 and earlier applications regardless of whether or not you are debugging within Visual Studio. However, starting with Microsoft .NET 4.0 and Visual Studio 2010, a native debugger is always attached when debugging a managed application in Visual Studio. As only a single native debugger may capture OutputDebugString messages, Harvester will not be able to capture log messages if debugging your application in Visual Studio 2010.
In order to capture log messages for a Microsoft .NET 4.0 or latter application while debugging use the Harvester Target documented below.
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target xsi:type="OutputDebugString" name="DbWin" layout="Log4JXmlEventLayout">
<layout xsi:type="Log4JXmlEventLayout">
</layout>
</target>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="DbWin"/>
</rules>
</nlog>
Note: Harvester will capture all application output regardless of message format, but for optimal results, a layout of Log4JXmlEventLayout should be used.
Harvester Target
Recommended for Microsoft .NET 4.0 or later applications!
Harvester provides a custom target to facilitate capturing log messages regardless of whether or not a native debugger is attached. The Harvester target allows you to configure the type of message buffer used along with the corresponding binding and mutex name.
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<extensions>
<add assembly="Harvester.Integration.NLog, Version=2.1.1.0, Culture=neutral, PublicKeyToken=2335e074c59acad6"/>
</extensions>
<targets>
<target xsi:type="Harvester" name="Harvester" bufferType="NamedPipeBuffer" binding ="\\.\pipe\Harvester" mutexName="HarvesterMutex" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="Harvester" />
</rules>
</nlog>
Binding
A valid binding must be provided based on the selected buffer type.
- NamedPipeBuffer - Must be a valid local pipe name (i.e., \\.\pipe\SomeName).
- SharedMemoryBuffer - Must be a valid memory mapped file name (i.e., Local\SomeName or Global\SomeName).
Note: A binding name must correspond to a configured Harvester listener.
BufferType
Currently two buffer types are supported:
- NamedPipeBuffer - Recommend buffer type for all applications.
- SharedMemoryBuffer - Legacy buffer type supported by Harvester prior to version 2.0.0.
Note: Using a SharedMemoryBuffer for applications hosted in IIS is not supported.
MutexName
The mutex name that correspond to the bound Harvester listener.
IMPORTANT: The Harvester mutex uses `LOCAL\` scope by default; change the MutexName to `GLOBAL\HarvesterMutex` if the mutex must be shared across multiple user sessions (i.e., capturing log messages from IIS, Windows Services or any other user session).
The corresponding <listener /> element in the Harvester configuration file(s) may also need to be updated from `HarvesterMutex` to `GLOBAL\HarvesterMutex`.