Log Service Implementation
In this article:
- void SetLogService(ILogService logService)
LS Pay logs various information regarding the communication to devices and for tracking. This is implemented in a LogService. Logs are not stored in LS Pay and to access them a service must be injected into the EAManagement when the object is created.
The LogService interface is shown here:
namespace LSPay.Engine.Domain.Services
{
/// <summary>
/// Logging service that the Payment Engine uses to output logs.
/// </summary>
public interface ILogService
{
/// <summary>
/// Log the specified time stamp, log level and message.
/// </summary>
/// <param name="timeStamp">Time stamp.</param>
/// <param name="logLevel">Log level.</param>
/// <param name="message">Message.</param>
void Log(DateTime timeStamp, LoggingLevel logLevel, string message);
}
public enum LoggingLevel
{
/// <summary>
/// Designates finer-grained informational events than the DEBUG.
/// </summary>
TRACE = 0,
/// <summary>
/// Designates fine-grained informational events that are most useful to debug an application.
/// </summary>
DEBUG = 1,
/// <summary>
/// Designates informational messages that highlight the progress of the application at coarse-grained level.
/// </summary>
INFO = 2,
/// <summary>
/// Designates potentially harmful situations.
/// </summary>
WARNING = 3,
/// <summary>
/// Designates error events that might still allow the application to continue running.
/// </summary>
ERROR = 4,
/// <summary>
/// Designates very severe error events that will presumably lead the application to abort.
/// </summary>
FATAL = 5
}
}
Create an implementation of the LogService referencing the ILogService
interface, and call the function SetLogService()
in EAManagement.
LS Pay has one logging mechanism that can be individually set for each plugin to log into separate files.
A simple implementation might be storing the logs in a .txt file or in a SQLite database. The log files are a good source to find out what might be happening in LS Pay, if irregularities happen.
Note: Although LS Pay will work without setting a log service, it is not recommended as the log service will help to resolve bugs and other problems, which might otherwise be difficult without detailed information.
Example from a WPF application where the log details are logged into a file:
public async Task SetupSelectedPlugin(PluginName pluginName)
{
try
{
currentEFTType = (ExternalAccessoryType)Enum.ToObject(typeof(ExternalAccessoryType), pluginName.DeviceId);
// Set path with the new unique id of the device connected
LSPay_WPF.Helpers.LogService.CreateLogDetails(pluginName.PluginUniqueId);
// Now create/switch between plugins with a handle to the correct type (item)
await engineService.SetupAsync(LSPay_WPF.Helpers.LogService.GetLogService(), PluginFactory.GetPluginFactory().GetEAM(currentEFTType, pluginName.NameOfPlugin));
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine("Plugin list setup exception: " + e.Message, e);
}
}