Created
July 11, 2014 13:14
-
-
Save CipherLab/1f55c841e540b87072ba to your computer and use it in GitHub Desktop.
Event logger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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