Logging
This section explains how logging services are organized in the OnixS .NET CME Drop Copy Handler.
NLog logging
The NLog library is used for Handler-level logging.
NLog could be configured either through a configuration file or programmatically.
NLog shutdown
NLog will, by default attempt to flush automatically at application shutdown. Microsoft Windows give .NET applications a limited amount of time to perform shutdown (usually 2 sec) before being terminated. If having an NLog configuration with NLog Targets that requires network-traffic (Http, Mail, TCP), then it is a really good idea to perform a manual Flush/Shutdown independent on running on Linux/Windows.
NLog.LogManager.Shutdown(); // Flush and close down internal threads and timers
.NET applications running on Mono/Linux are required to stop threads/timers before entering the application shutdown phase. Failing to do this will cause unhandled exceptions and segmentation faults, and other unpredictable behavior.
Example
For example (NLog.config):
<?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" throwConfigExceptions="true">
<targets>
<target name="logfile" xsi:type="File" fileName="CmeMdHandlerLog.txt" deleteOldFileOnStartup="false"
layout="${date:universalTime=true:format=yyyyMMdd-HH\:mm\:ss.ffffff}|${level:uppercase=true}|${logger}|${message}"/>
<target name="logconsole" xsi:type="Console" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logconsole" />
<logger name="*" minlevel="Trace" writeTo="logfile" />
</rules>
</nlog>