error in window service while starting. [Resolved]

Posted by Sahoo under C# on 2/26/2012 | Points: 10 | Views : 7531 | Status : [Member] | Replies : 2
Hi

I have wrote a window service and it giving error while start.

Error:The Service on local computer started and then stopped ,Some services stop automatically if there are not in use by other services or programs.

I also got error detail in window log as:

Service cannot be started. System.ArgumentException: The source 'SampleWindowService' is not registered in log 'windowLogDemo'. (It is registered in log 'DemoService'.) " The Source and Log properties must be matched, or you may set Log to the empty string, and it will automatically be matched to the Source property. at System.Diagnostics.EventLogInternal.VerifyAndCreateSource(String sourceName, String currentMachineName) at System.Diagnostics.EventLogInternal.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData) at System.Diagnostics.EventLog.WriteEntry(String message) at WindowsServiceDemo.Service1.OnStart(String[] args) at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)

log is not full.So no memory issue is there I think.

my code goes here:

private const string sourceName = "SampleWindowService";
protected override void OnStart(string[] args)
{
if (!System.Diagnostics.EventLog.SourceExists(sourceName))
{
System.Diagnostics.EventLog.CreateEventSource(sourceName,"DemoService");
}
this.eventLog1.Source = sourceName;
// this.eventLog1.Log = "windowLogDemo";
this.eventLog1.WriteEntry("Service started successfully");

//timer setting...
myTimer.Start();
myTimer.Interval = 60000;
myTimer.Elapsed += new ElapsedEventHandler(timer1_Elapsed);
}

please suggest.




Responses

Posted by: Blessyjees on: 2/27/2012 [Member] Bronze | Points: 50

Up
0
Down

Resolved
Hi

Try this

private const string sourceName = "SampleWindowService"; 

protected override void OnStart(string[] args)
{
if (!System.Diagnostics.EventLog.SourceExists(sourceName))
{
System.Diagnostics.EventLog.CreateEventSource(sourceName,"DemoService");
}
this.eventLog1.Source = sourceName;
this.eventLog1.Log ="DemoService";
this.eventLog1.WriteEntry("Service started successfully");

//timer setting...
myTimer.Start();
myTimer.Interval = 60000;
myTimer.Elapsed += new ElapsedEventHandler(timer1_Elapsed);
}


Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Sahoo, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sahoo on: 2/27/2012 [Member] Starter | Points: 25

Up
0
Down
thanks for ur replay.
it solved my problem.

Sahoo, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response