Made DefaultLogger use the eventlog rather than debug.writeline(..) renamed service1 to CardReaderService #22
152 lines
4.9 KiB
C#
152 lines
4.9 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using Interfaces;
|
|
|
|
namespace CardReaderService.DefaultComponents
|
|
{
|
|
public class DefaultLogger : ILogger
|
|
{
|
|
private string _eventLogSource = "CardRdrSvc";
|
|
private string _logName = "CardReaderServiceLog";
|
|
private EventLog _eventLog;
|
|
|
|
public DefaultLogger()
|
|
{
|
|
if (!EventLog.SourceExists(_eventLogSource))
|
|
{
|
|
EventLog.CreateEventSource(_eventLogSource, _logName);
|
|
}
|
|
}
|
|
public bool IsDebugEnabled { get { return true; } }
|
|
public bool IsErrorEnabled { get { return true; } }
|
|
public bool IsFatalEnabled { get { return true; } }
|
|
public bool IsInfoEnabled { get { return true; } }
|
|
public bool IsTraceEnabled { get { return true; } }
|
|
public bool IsWarnEnabled { get { return true; } }
|
|
|
|
public void Debug(Exception exception)
|
|
{
|
|
CheckEventLog();
|
|
_eventLog.WriteEntry(exception.ToString(), EventLogEntryType.Information);
|
|
}
|
|
|
|
public void Debug(string format, params object[] args)
|
|
{
|
|
CheckEventLog();
|
|
_eventLog.WriteEntry(string.Format(format, args), EventLogEntryType.Information);
|
|
}
|
|
|
|
public void Debug(Exception exception, string format, params object[] args)
|
|
{
|
|
CheckEventLog();
|
|
_eventLog.WriteEntry(string.Format(exception + ", " + format, args),
|
|
EventLogEntryType.Information);
|
|
}
|
|
|
|
public void Error(Exception exception)
|
|
{
|
|
CheckEventLog();
|
|
_eventLog.WriteEntry(exception.ToString(), EventLogEntryType.Error);
|
|
}
|
|
|
|
public void Error(string format, params object[] args)
|
|
{
|
|
CheckEventLog();
|
|
_eventLog.WriteEntry(string.Format(format, args), EventLogEntryType.Error);
|
|
}
|
|
|
|
public void Error(Exception exception, string format, params object[] args)
|
|
{
|
|
CheckEventLog();
|
|
_eventLog.WriteEntry(string.Format(exception + ", " + format, args),
|
|
EventLogEntryType.Error);
|
|
}
|
|
|
|
public void Fatal(Exception exception)
|
|
{
|
|
CheckEventLog();
|
|
_eventLog.WriteEntry(exception.ToString(), EventLogEntryType.Error);
|
|
}
|
|
|
|
public void Fatal(string format, params object[] args)
|
|
{
|
|
CheckEventLog();
|
|
_eventLog.WriteEntry(string.Format(format, args), EventLogEntryType.Error);
|
|
}
|
|
|
|
public void Fatal(Exception exception, string format, params object[] args)
|
|
{
|
|
CheckEventLog();
|
|
_eventLog.WriteEntry(string.Format(exception + ", " + format, args),
|
|
EventLogEntryType.Error);
|
|
}
|
|
|
|
public void Info(Exception exception)
|
|
{
|
|
CheckEventLog();
|
|
_eventLog.WriteEntry(exception.ToString(), EventLogEntryType.Information);
|
|
}
|
|
|
|
public void Info(string format, params object[] args)
|
|
{
|
|
CheckEventLog();
|
|
_eventLog.WriteEntry(string.Format(format, args), EventLogEntryType.Information);
|
|
}
|
|
|
|
public void Info(Exception exception, string format, params object[] args)
|
|
{
|
|
CheckEventLog();
|
|
_eventLog.WriteEntry(string.Format(exception + ", " + format, args),
|
|
EventLogEntryType.Information);
|
|
}
|
|
|
|
public void Trace(Exception exception)
|
|
{
|
|
CheckEventLog();
|
|
_eventLog.WriteEntry(exception.ToString(), EventLogEntryType.Information);
|
|
}
|
|
|
|
public void Trace(string format, params object[] args)
|
|
{
|
|
CheckEventLog();
|
|
_eventLog.WriteEntry(string.Format(format, args), EventLogEntryType.Information);
|
|
}
|
|
|
|
public void Trace(Exception exception, string format, params object[] args)
|
|
{
|
|
CheckEventLog();
|
|
_eventLog.WriteEntry(string.Format(exception + ", " + format, args),
|
|
EventLogEntryType.Information);
|
|
}
|
|
|
|
public void Warn(Exception exception)
|
|
{
|
|
CheckEventLog();
|
|
_eventLog.WriteEntry(exception.ToString(), EventLogEntryType.Warning);
|
|
}
|
|
|
|
public void Warn(string format, params object[] args)
|
|
{
|
|
CheckEventLog();
|
|
_eventLog.WriteEntry(string.Format(format, args), EventLogEntryType.Warning);
|
|
}
|
|
|
|
public void Warn(Exception exception, string format, params object[] args)
|
|
{
|
|
CheckEventLog();
|
|
_eventLog.WriteEntry(string.Format(exception + ", " + format, args),
|
|
EventLogEntryType.Warning);
|
|
}
|
|
|
|
private void CheckEventLog()
|
|
{
|
|
if (_eventLog == null)
|
|
{
|
|
_eventLog = new EventLog();
|
|
_eventLog.Source = _eventLogSource;
|
|
_eventLog.Log = _logName;
|
|
}
|
|
}
|
|
}
|
|
}
|