-
Notifications
You must be signed in to change notification settings - Fork 9
Logging HOWTO
mrdavidlaing edited this page Feb 2, 2012
·
11 revisions
CIAPI.CS logs all of its API interactions in a manner that is intended to help diagnose API connection issues.
In order to trap these log messages you need to attach CIAPI.CS's logger to your log framework of choice. CIAPI.CS supports any log framework that exposes a standard ILog interface. It is straight forward to write an adapter to interface with other log frameworks.
//replace the default DebugLogger with Log4Net which implements an ILog style interface
LogManager.CreateInnerLogger = (logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat) =>
{
// create external logger implementation and return instance.
// this will be called whenever CIAPI requires a logger
return log4net.LogManager.GetLogger(logName);
};
See https://github.com/cityindex/CIAPI.CS/blob/master/src/CIAPI.IntegrationTests/LoggingFixture.cs for further details
- Create a [Logger based on AbstractLogger](https://github.com/cityindex/CIAPI.CS/blob/master/src/Phone7/Tests%20And%20Samples/PhoneApp1%20(1\)/SimpleDebugAppender.cs)
public class SimpleDebugAppender : AbstractAppender
{
public SimpleDebugAppender(string logName, LogLevel logLevel, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat)
: base(logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat)
{
}
protected override void WriteInternal(LogLevel level, object message, Exception exception)
{
var sb = new StringBuilder();
FormatOutput(sb, level, message, exception);
System.Diagnostics.Debug.WriteLine(sb.ToString());
}
}
- Attach this to LogManager
//Hook up a logger for the CIAPI.CS libraries
LogManager.CreateInnerLogger = (logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat)
=> new SimpleDebugAppender(logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat);
See https://github.com/cityindex/CIAPI.CS/tree/master/src/Phone7/Tests%20And%20Samples/PhoneApp1%20(1) for further details