我开发了一个32位服务,我在Windows 7 Home Premium x64上运行它。 问题是当我启动它,窗口给我以下消息Windows服务自动启动和停止,异常处理问题
本地计算机上的WLConsumer服务启动,然后停止。如果某些服务未被其他服务或程序使用,则会自动停止 。
我发现在事件以下信息登录
服务无法启动。 System.ArgumentException:日志WLConsumer已被注册为本地计算机上的源。 在System.Diagnostics.EventLogInternal.CreateEventSource(EventSourceCreationData sourceData) 在System.Diagnostics.EventLogInternal.VerifyAndCreateSource(字符串SOURCENAME,字符串currentMachineName) 在System.Diagnostics.EventLogInternal.WriteEntry(字符串消息,EventLogEntryType类型,事件ID的Int32,Int16类型类别(x86)\ CSI中的WeblogicConsumerService.WeblogicConsumer.winEventlogMe(字符串logTxt,字符串logSrc,Char entryType) 处的System.Diagnostics.EventLog.WriteEntry(字符串消息,EventLogEntryType类型) \ WeblogicConsumerService \ WeblogicConsumer.cs:line 136 at C:\ Program Files(x86)\ CSI \ WeblogicConsumerService \ WeblogicConsumer.cs中的WeblogicConsumerService.WeblogicConsumer.OnStart(String [] args):line 63 at System.Serv iceProcess.ServiceBase.ServiceQueuedMainCallback(对象状态)
这是我在的OnStart()方法
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是我打电话给记录的方法。
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
}
当我在OnStart()方法中注释掉对winEventLogMe()方法的调用时,服务启动时不会出错。所以显然winEventLogMe()方法有些问题。 有人可以帮我找出最新的问题,因为我现在对如何解决这个问题完全无能为力。
thanx提前:)
@nick_w我已经编辑我的代码,如你所说,该服务成功地启动。但在停止它时,我收到以下消息:
无法停止服务。 System.ArgumentException:源'WLConsumer2012'未在日志'ServiceStop'中注册。 (它在“SeriviceStartup”日志中注册。)“Source和Log属性必须匹配,或者您可以将Log设置为空字符串,并且它将自动匹配到Source属性 at System.Diagnostics.EventLogInternal。在System.Diagnostics.EventLogInternal.WriteEntry(字符串消息,EventLogEntryType类型,Int32 eventID,Int16类别,字节[] rawData) 在System.Diagnostics.EventLog.WriteEntry(字符串消息,EventLogEntryType类型)验证字符串(字符串sourceName,字符串currentMachineName) )在C:\ Program Files(x86)\ CSI \ WeblogicConsumerService \ WeblogicConsumer中的WeblogicConsumerService.WeblogicConsumer.winEventlogMe(String logTxt,String logSrc,Char entryType)处的 。CS:线139 在WeblogicConsumerService.WeblogicConsumer.OnStop()在C:\程序文件(x86)\ CSI \ WeblogicConsumerService \ WeblogicConsumer.cs:线70 在System.ServiceProcess.ServiceBase.DeferredStop()
这里是OnStop()方法
protected override void OnStop()
{
winEventlogMe("Successful stop", "ServiceStop", 'i');
}
这些事件日志开始混淆了我很多。我已经完成了登录其他服务的相同方法,并且从未遇到过这样的问题。我怎样才能在这个服务中收到这些错误但其没有太大的所有其他我曾经做过:(不同
如果你仍然在这个问题上的工作,看看在我最近的编辑。 –