Log4Net Configuration

Integrating your application with Harvester is as easy as adding an additional appender to the Log4Net configuration section.

Typical Configuration

The typical configuration requires that Log4Net be configured with an OutputDebugString appender.

<log4net>
  <appender name="OutputDebugStringAppender" type="log4net.Appender.OutputDebugStringAppender" >
    <layout type="log4net.Layout.XMLLayout" />
  </appender>
  <root>
    <level value="DEBUG" />
    <appender-ref ref="OutputDebugStringAppender" />
  </root>
 </log4net>
IMPORTANT: Harvester will capture all output regardless of message format, but for optimal results, a layout of XmlLayout should be used.

When using applications developed against the Microsoft .NET Framework 3.5 or earlier, all output will be captured by Harvester regardless of whether or not a debugger has been attached (i.e., launched via F5 or CTRL-F5). However, if developing an application with the Microsoft .NET Framework 4.0 or later, output will NOT be captured by Harvester when a debugger has been attached (i.e., launched with F5). If you prefer to not use the custom appender documented below, launch your application without the debugger (i.e., CRTL-F5) to capture log output in Harvester.

Why is my Microsoft .NET 4.0+ Application Not Capturing Output When Debugging!

With the latest version of the CLR, Microsoft has opted to always attach a Native debugger when you are debugging your managed application(s) in Visual Studio 2010. As only a single native debugger may be attached to a given process at any one time, Harvester cannot capture the OutputDebugString messages from your application when launched in Visual Studio with a debugger attached (i.e., launched with F5). To work around the issue, a custom Log4Net appender has been created that will capture all OutputDebugString messages and write them to a separate message buffer that Harvester can capture regardless of a debugger being attached to your application.

<log4net>
  <appender
    name="HarvesterAppender" 
    type="Harvester.Integration.Log4Net.HarvesterAppender, Harvester.Integration.Log4Net, 
          Version=1.1.188.834, Culture=neutral, PublicKeyToken=2335e074c59acad6" />
  <root>
    <level value="DEBUG" />
    <appender-ref ref="HarvesterAppender" />
  </root>
</log4net>
IMPORTANT: Harvester will capture all output regardless of message format, but for optimal results, a layout of XmlLayoutSchemaLog4j must be used (default).

Last edited Aug 19, 2011 at 12:42 AM by CBaxter, version 2

Comments

HakanL Aug 27, 2013 at 12:09 AM 
The example seems out-dated (version 1.1...)