Setting Up Logging

The SDK uses the Apache Common Infrastructure Libraries for .NET which provides a common interface for logging adapters. In order to use logging within the SDK, you will need to reference the packages for the adapter you wish to use. The following defines the process for using the Log4Net Adapter with the SDK:

  1. Using the Nuget Package Manager in Visual Studio, include the following package in your project: Common.Logging.Log4Net
  2. In your App.Config or Web.Config, add the following elements between the <configuration></configuration> so that your config looks like this:
    
     <?xml version="1.0" encoding="utf-8" ?>
     <configuration>
       <configSections>
         <sectionGroup name="common">
           <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
         </sectionGroup>
         <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
       </configSections>
       <common>
         <logging>
           <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
             <arg key="configType" value="INLINE" />
           </factoryAdapter>
         </logging>
       </common>
       <log4net>
         <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender,log4net">
           <layout type="log4net.Layout.PatternLayout,log4net">
             <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] <%X{auth}> - %m%n" />
           </layout>
         </appender>
         <root>
           <priority value="ALL" />
           <level value="DEBUG" />
           <appender-ref ref="ConsoleAppender" />
         </root>
      </log4net>
      <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
         </startup>
     </configuration>
                        
    Note: Note that in this example, we are creating a FileAppender; there are a wide variety of possible appenders and configuration options you can customize to your liking. For more information regarding customizing your configuration, please check out the Log4Net documentation found here.