Click or drag to resize
Logging & Tracing

SphinxConnector.NET uses the Common.Logging library to output its log messages. The purpose of the Common.Logging library is to provide an abtraction layer over several logging frameworks, namely:

This approach has the advantage that SphinxConnector.NET doesn't force a logging framework on you, but rather lets you choose the right one for your needs. Also, if you are already using a logging framework, chances are that Common.Logging supports it and you can easily send SphinxConnector.NET log messages to it.

Setting up Logging

This section is intended to be a short introduction on how to setup common logging in your application. For a full reference and guides please refer to the Common.Logging documentation in the SphinxConnector.NET installation directory.

Logging can be configured either in an app.config file or programmatically. In this example we'll use the app.config file to setup logging with NLog. First we need to add the config sections for NLog and Common.Logging to the config file:

Config sections
  <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
  <sectionGroup name="common">
    <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />

We then add the configuration for the Common.Logging library:

Common.Logging config
    <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog">
      <arg key="configType" value="INLINE" />

This tells Common.Logging that it should use NLog to output the log messages and that the NLog configuration is placed in the same config file (option configType). Finally we add the NLog config section:

NLog config
<nlog xmlns="" xmlns:xsi="" autoReload="true" throwExceptions="false">
      <target name="console" xsi:type="Console" layout="${longdate} ${level:uppercase=true} ${callsite} ${message} ${exception:format=tostring}"/>
      <logger name="*" minlevel="Trace" writeTo="console"> </logger>

The NLog configuration is straightforward: We setup a console target and a catch-all logger with a mininum log level of Trace.

Note Note

In a production environment the log level generally should not be set lower than Info except for debugging puposes, because Trace is very verbose and may slow down your application.