Skip to content

Instantly share code, notes, and snippets.

@CipherLab
Created July 11, 2014 13:14
Show Gist options
  • Save CipherLab/1f55c841e540b87072ba to your computer and use it in GitHub Desktop.
Save CipherLab/1f55c841e540b87072ba to your computer and use it in GitHub Desktop.
Event logger
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
public static class EventLogger
{
private static EventLog log;
public static void Log(string message)
{
try
{
if (log == null)
InitEventLog("Default");
log.WriteEntry(message);
}
catch { }
}
public static void Log(string message, string name)
{
try
{
InitEventLog(name);
log.WriteEntry(message);
}
catch { }
}
private static void InitEventLog(string name)
{
try
{
string sSource = name;
string sLog = "Application";
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
log = new EventLog();
log.Source = sSource;
log.Log = sLog;
}
catch { }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment