I developed a 32-bit service, I run it on Windows 7 Home Premium x64. The problem is when I run it, windows give me the following message
The WLConsumer service on the local computer started and then stopped. Some services stop automatically if they are not used by other services or programs.
In the event log I found the following message
The service cannot be started. System.ArgumentException: The WLConsumer log is already registered as a source on the local computer. in System.Diagnostics.EventLogInternal.CreateEventSource (EventSourceCreationData sourceData) in System.Diagnostics.EventLogInternal.VerifyAndCreateSource (String sourceName, String currentMachineName) in System.Diagnostics, Intent, EventEntryTementry (Event ] rawData) in System.Diagnostics.EventLog.WriteEntry (String message, type EventLogEntryType) in WeblogicConsumerService.WeblogicConsumer.winEventlogMe (String logTxt, String logSrc, Char entryType) in C: \ Program Files (x86) \ CSI \ Logic Weblog cs: line 136 in WeblogicConsumerService.WeblogicConsumer.OnStart (String [] args) in C: \ Program Files (x86) \ CSI \ WeblogicConsumerService \ WeblogicConsumer.cs: line 63 in System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback (object state)
This is my code block in the OnStart () method
protected override void OnStart(string[] args) { #region WEBLOGIC CREDENTIALS try { //Weblogic URL this.url = Registry.LocalMachine.OpenSubKey(@"Software\CSI_WL").GetValue("URL").ToString(); //Queue name this.qName = Registry.LocalMachine.OpenSubKey(@"Software\CSI_WL").GetValue("Queue").ToString(); //Weblogic login name this.user = Registry.LocalMachine.OpenSubKey(@"Software\CSI_WL").GetValue("User").ToString(); //Weblogic password this.pwd = Registry.LocalMachine.OpenSubKey(@"Software\CSI_WL").GetValue("Pwd").ToString(); //Weblogic Connection Factory this.cfName = Registry.LocalMachine.OpenSubKey(@"Software\CSI_WL").GetValue("ConnectionFactory").ToString(); //root folder this.rFolder = Registry.LocalMachine.OpenSubKey(@"Software\CSI_WL").GetValue("root").ToString(); } catch (Exception e) { winEventlogMe(e.Message, "WLRegistryKeys", 'e'); } #endregion winEventlogMe("Successful start", "SeriviceStartup", 'i'); synchro.Enabled = true; }
winEventLogMe is the method that I call to log.
public static void winEventlogMe(string logTxt, string logSrc, char entryType) { #region Log //Log to event log EventLog theEvent = new EventLog("WLConsumer"); theEvent.Source = logSrc; if (entryType == 'e') theEvent.WriteEntry(logTxt, EventLogEntryType.Error); else if (entryType == 'i') theEvent.WriteEntry(logTxt, EventLogEntryType.Information); else if (entryType == 'w') theEvent.WriteEntry(logTxt, EventLogEntryType.Warning); else theEvent.WriteEntry(logTxt, EventLogEntryType.Error);*/ #endregion }
When I comment on calls to the winEventLogMe () method in the OnStart () method, the service starts without error. Thus, it is obvious that something is wrong with the winEventLogMe () method. Can someone please help me figure out what the problem is, because I have absolutely no idea how to solve this problem now.
thanx in advance :)
@nick_w I edited my code, as you suggested, the service started successfully. But when stopping, I received the following message:
Failed to stop the service. System.ArgumentException: WLConsumer2012 source is not registered in the ServiceStop log. (It is registered in the SeriviceStartup journal.) "The Source and Log properties must be mapped or you can set Log to an empty string and it will be mapped automatically to the original property. In System.Diagnostics.EventLogInternal.VerifyAndCreateSource (String sourceName, String currentMachineName) in System.Diagnostics.EventLogInternal.WriteEntry (String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte [] rawData) in System.Diagnostics.EventLog.WriteEntry (String message, Type EventLogEntryTypeWebloglogloggerloglog.loglogerloglog.loglogserviceloglog.blog (String logTxt, String logSrc, Char entryType) in C: \ Program Files (x86) \ CSI \ WeblogicConsumerService \ WeblogicConsumer.cs: line 139 in WeblogicConsumerService.WeblogicConsumer.OnStop () in C: \ Program Files (x86) \ CSI \ Weblogicconsu merService \ WeblogicConsumer.cs: line 70 in System.ServiceProcess.ServiceBase.DeferredStop ()
here the OnStop () method is used
protected override void OnStop() { winEventlogMe("Successful stop", "ServiceStop", 'i'); }
These event logs scare me. I made the same registration method in other services and have never encountered such problems. How can I get these errors in this service, but it is not much different from all the others that I made :(