Skip to content

Instantly share code, notes, and snippets.

@2garryn
Created October 2, 2020 10:14
Show Gist options
  • Save 2garryn/5052a364c965e36c5ea7c268c9376a36 to your computer and use it in GitHub Desktop.
Save 2garryn/5052a364c965e36c5ea7c268c9376a36 to your computer and use it in GitHub Desktop.
class Logger
{
private static volatile Logger instance;
private EventLog _evLog;
private static object lockObject = new object();
public Logger(string logApp, string source)
{
if (!EventLog.SourceExists(source))
EventLog.CreateEventSource(source, logApp);
_evLog = new EventLog(logApp)
{
Source = source
};
}
public void Info(string format, params object[] args)
=> Write(EventLogEntryType.Information, format, args);
public void Warning(string format, params object[] args)
=> Write(EventLogEntryType.Warning, format, args);
public void Error(string format, params object[] args)
=> Write(EventLogEntryType.Error, format, args);
private void Write(EventLogEntryType t, string format, params object[] args)
=> _evLog.WriteEntry(String.Format(format, args), t);
public void Dispose() => _evLog.Dispose();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment