I have a windows service. It was working fine until I added code for it to begin logging. Now when I try to start the service I receive the following error:
The GBBService service on local computer started then stopped. Some services stopped automatically if they have no work to do, for example, the performance logs and alert service
Here is the code for my service: - From inside project installer
public partial class ProjectInstaller : System.Configuration.Install.Installer
{
string eventSource = "GBBServiceLog";
public ProjectInstaller()
{
InitializeComponent();
EventLogInstaller installer = FindInstaller(this.Installers);
if (installer != null)
{
installer.Source = eventSource;
installer.Log = "My GBBServiceLog";
}
}
private EventLogInstaller FindInstaller(InstallerCollection installers)
{
foreach (Installer installer in installers)
{
if (installer is EventLogInstaller)
{
return (EventLogInstaller)installer;
}
EventLogInstaller eventLogInstaller = FindInstaller(installer.Installers);
if (eventLogInstaller != null)
return eventLogInstaller;
}
return null;
}
protected override void OnCommitted(IDictionary savedState)
{
base.OnCommitted(savedState);
// Start the service after installation
using (ServiceController sc = new ServiceController(this.serviceInstaller1.ServiceName))
{
sc.Start();
}
}
}
From within my service:
public GBBService()
{
InitializeComponent();
EventLog.Source = eventSource;
EventLog.Log = "My GBB Service Log";
}
protected override void OnStart(string[] args)
{
EventLog.WriteEntry("GBBService Service Started");
}
Did I do something wrong in my code?