Common Logging

From Hiasobi - FHIR
Jump to: navigation, search

Common Logging

Supported as follows:

  • Common.Logging.dll (v2.1.1.0) built in
  • External adapters e.g. NLog - Common.Logging.NLog20.dll
  • Configuration: <app>.exe.config - configure logging
  • Default is no logging (null logger)

NLog Configuration

Require libraries and configuration

  • Common.Logging.NLog20.dll - NLog2 common logging adapter
  • NLog.dll - NLog2 core library
  • NLog.config - external configuration file for NLog; (may be done in-line in the <app>.exe.config)
  • <app>.exe.config - inject dependency and reference NLog.cofig external file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
      <sectionGroup name="common">
        <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
      </sectionGroup>
  </configSections>
  <common>
    <logging>
      <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20">
        <arg key="configType" value="FILE" />
        <arg key="configFile" value="NLog.config" />
      </factoryAdapter>
    </logging>
  </common>
</configuration>

NLog Typical Configuration

The typical logging location for Hiasobi. 7 day rolling log in the %AppData%\<adapter name>\logs folder.

  • Current log: log.today.txt
  • Past logs: log.<n>.txt
  • e.g. log.0.txt, log.1.txt, ..., log.6.txt - most recent to oldest logs


<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <targets>  
   <target xsi:type="File" 
         name="userlog" layout="${longdate} ${logger} ${message} ${exception:Message,StackTrace}" 
         fileName="${specialfolder:ApplicationData}/<adapter name>/logs/log.today.txt" 
         archiveFileName="${specialfolder:ApplicationData}/TelstraRunner/logs/log.{#}.txt" 
         archiveEvery="Day" archiveNumbering="Rolling" maxArchiveFiles="7" concurrentWrites="true" />
   <target xsi:type="Console" name="console" />
 </targets>
 <rules>
   <logger name="*" minlevel="Trace" writeTo="userlog" />
 </rules>
</nlog>