|
|
| C# | Using system event log | Top |
Using system event log Using System.Diagnostics; namespace SCP { public class UseEventLog { private EventLog Log1; /// <summary> /// The Event source will be register with the local computer /// </summary> /// <param name="SourceName"></param> /// <param name="LogName"></param> public UseEventLog(string SourceName,string LogName) { Log1=new EventLog(); //check if an event log already exists for this source if (EventLog.SourceExists(SourceName)== false) { /* For LogName: Application, Security, System, or a custom event log can be use. If you do not specify a value, the logName defaults to Application. */ EventLog.CreateEventSource(SourceName,LogName); } //set SourceName as source for Log1 Log1.Source=SourceName; } /// <summary> /// This overload of UseEventLog uses /// MachineName: The name of the computer to register the event source with. /// "." can be specify for the local computer. /// </summary> public UseEventLog(string SourceName,string LogName,string MachineName) { Log1=new EventLog(); //check if an event log already exists for this source if (EventLog.SourceExists(SourceName,MachineName)==false) { /* For LogName: Application, Security, System, or a custom event log can be use. If you do not specify a value, the logName defaults to Application. */ EventLog.CreateEventSource(SourceName,LogName,MachineName); } //set SourceName as source for Log1 Log1.Source=SourceName; } } public void LogMessage(string Message) { Log1.WriteEntry(Message); } }
|
|
|
|