Click or drag to resize

Logging Concept

This page explains the logging concept used in the xServer .NET Framework.

This page contains the following sections:

Background

For logging runtime information of the xServer.Net components, classes of System.Diagnostics namespace are used. For each class providing logging information, an own singleton instance of TraceSource is provided.

Concerning the trace leveling (consisting of the levels None, Critical, Error, Warning, Information, Verbose and All), a customized set of switches can be set, according the current situation to analyze.

The setting is configurable by means of the app config file, which name is modified after client-side deployment by adding the extension *.config to the complete execution file name: MyApplication.exe.config. Besides other information, it can contain a separate XML node <System.Diagnostics>, as a child of the root node <configuration>. This node may contain all trace sources, i.e. all classes which are able of logging, and an individual set of trace switches cutomizing the trace level for each of these sources.

The following sample includes the trace sources of the classes WmsMapService, XMapTiledProvider, RemoteTiledProvider, XMapMetaInfo and ThreadPool, whereby the trace sources' names are set according their corresponding class name. The trace source for the ThreadPool class has an own switch with a more verbose leveling, because it addresses a situation for getting a more detailed view of the ThreadPool class:

Setting the application theme.
<configuration>
  <system.diagnostics>
    <sources>
      <source name="WmsMapService" switchName="General" switchType="System.Diagnostics.SourceSwitch">
        <listeners>
          <add name="Console"/>
          <add name="File"/>
          <remove name="Default"/>
        </listeners>
      </source>

      <source name="XMapTiledProvider" switchName="General" switchType="System.Diagnostics.SourceSwitch">
        <listeners>
          <add name="Console"/>
          <add name="File"/>
          <remove name="Default"/>
        </listeners>
      </source>

      <source name="RemoteTiledProvider" switchName="General" switchType="System.Diagnostics.SourceSwitch">
        <listeners>
          <add name="Console"/>
          <add name="File"/>
          <remove name="Default"/>
        </listeners>
      </source>

      <source name="XMapMetaInfo" switchName="General" switchType="System.Diagnostics.SourceSwitch">
        <listeners>
          <add name="Console"/>
          <add name="File"/>
          <remove name="Default"/>
        </listeners>
      </source>

      <source name="ThreadPool" switchName="ThreadPool" switchType="System.Diagnostics.SourceSwitch">
        <listeners>
          <add name="Console"/>
          <add name="File"/>
          <remove name="Default"/>
        </listeners>
      </source>
    </sources>

    <switches>
      <add name="General" value="Error"/>
      <add name="ThreadPool" value="Information"/>
    </switches>

    <sharedListeners>
      <add name="Console" type="System.Diagnostics.ConsoleTraceListener">
        <filter type="System.Diagnostics.EventTypeFilter" initializeData="All"/>
      </add>
      <add name="File" type="System.Diagnostics.TextWriterTraceListener" initializeData="myListener.log">
        <filter type="System.Diagnostics.EventTypeFilter" initializeData="All"/>
      </add>
    </sharedListeners>
  </system.diagnostics>
</configuration>

Remarkable is the definition of a pool for shared listeners, which can be used in multiple trace sources. In the example above, for each source a console listener (showing content in the debug view of development environment) and a file writer is set, and the default listener is removed. Naturally, each source could be configured with an individual set of listeners.

The logging settings can be modified without recompiling the application. So, for supporting purposes it is easy to modify the settings according the actual situation on an erroneous client system. After setting changes, the corresponding application has to be restarted.