Tuesday, July 10, 2012

Creating and Using EventLog in WindowService

First Drag and Drop EventLog component into Component design from ToolBox 


Event log (named : eventLog1) is added into you component class.


Create New Event Log in your window service Component class


 public EmployeeStatusService()
 {
     InitializeComponent();
     if (!System.Diagnostics.EventLog.SourceExists("MyLogInfo"))
     {
          System.Diagnostics.EventLog.CreateEventSource(
                    "MyLogInfo", "HirenLog");
     }
     eventLog1.Source = "SmartNetDeviceInfo";
     eventLog1.Log = "SmartNetLog";
 } 

Write Log entry on created log


 protected override void OnStart(string[] args)
 {
     eventLog1.WriteEntry("Service Started");
 } 

No comments:

Post a Comment