Logging
This section explains how logging services are organized in the OnixS .NET Core CME Market Data Handler.
NLog logging
The NLog library is used for Handler-level logging.
NLog could be configured either through a configuration file or programmatically.
Handler loggers
There are four NLog loggers used to make logging flexible.
- OnixS.CmeMdHandler
Logger controls Handler-related tracing and debug output.
- OnixS.CmeMdHandler.Receivers
Logger controls UDP receivers-related tracing and debug output. Received UDP packets in base 64 encoding will be added to log with Info level for log replay.
- OnixS.CmeMdHandler.FixMessages
Logger controls fix message processing-related tracing and debug output. Decoded fix messages will be added to log with Info level.
- OnixS.CmeMdHandler.OrderBook
Logger controls order books-related tracing and debug output.
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 a 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 Application running on Mono/Linux are required to stop threads/timers before entering 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>