Skip to content

Logging Overview

tylerje edited this page Oct 23, 2014 · 1 revision

ServiceWire hosts allow you to inject an ILog and IStats (see below) implementations upon construction. If you choose not to inject, the internal null implementation is used. If you inject the Logger and Stats classes as shown below, and then try to set the property to null, the setter will not throw but your instance will not be set to null. This is to prevent null reference exceptions.

To turn off logging, you can set your Loggger

 //interfaces for logging and stats collection for instrumentation
 
 public interface ILog
 {
    void Debug(string formattedMessage, params object[] args);
    void Info(string formattedMessage, params object[] args);
    void Warn(string formattedMessage, params object[] args);
    void Error(string formattedMessage, params object[] args);
    void Fatal(string formattedMessage, params object[] args);
 }
 
 public interface IStats
 {
    void Log(string name, float value);
    void Log(string category, string name, float value);
    void LogSys();
 }
 
 
 var logger = new Logger(logLevel: LogLevel.Debug);
 var stats = new Stats();
 
 var nphost = new NpHost(pipeName, logger, stats);
 //{...}
 
 //after injecting ServiceWire's default ILog
 logger.LogLevel = LogLevel.None;
 
 //{...}
 
 
 //NpHost and TcpHost ctor's
 public NpHost(string pipeName, ILog log = null, IStats stats = null)
 //{...}
 
 public TcpHost(int port, ILog log = null, IStats stats = null)
 //{...}

The ServiceWire Logger class implementat ILog and writes asynchronously to a text file that rolls by size or date or hour. It is a simple implementation that can be used to the extent that it is useful, but the reason the logger and stats interfaces are injectable in the host constructor is that the author expects that the serious user of ServiceWire will want to provide their own implementations.

Clone this wiki locally