Home > Deveploment and Programming > How to create Event Log in Service

How to create Event Log in Service

1. In a property of Class view select tool EventLog from Component Tab and drop in a class view.
2. Write the code  in a Constructor
For example.
 

public Class1()

{

// This call is required by the Windows.Forms Component Designer.

InitializeComponent();

 

if(!System.Diagnostics.EventLog.SourceExists(“FileMoveSourse”))

System.Diagnostics.EventLog.CreateEventSource(“FileMoveSourse”,

“FileMove”);

eventLog1.Source = “FileMoveSourse”;

// the event log source by which

//the application is registered on the computer

eventLog1.Log = “FileMove”;

 

// TODO: Add any initialization after the InitComponent call

}

3. Write code in onStart() method

eventLog1.WriteEntry(“my service started”);

4. Write code in onStop() method

eventLog1.WriteEntry(“my service stoped”);

Now after installation of service,You can check in eventLogger

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: