The class use the System.Diagnostics to write the message into the Event log.
using System.Diagnostics;
public class Logging
{
static string Source = "My Application";
public static void WriteEventLog(string Message, System.Diagnostics.EventLogEntryType EntryType){
try
{
if (!EventLog.SourceExists(Source))
{
EventLog.CreateEventSource(Source, "Application");
}
EventLog.WriteEntry(Source, Message, EntryType);
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
}
Usage:
Logging.WriteEventLog(System.Diagnostics.EventLogEntryType.Information,"Message Error");
Nessun commento:
Posta un commento