Windows服务启动,然后停止 [英] Windows service started and then stopped

查看:147
本文介绍了Windows服务启动,然后停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在开发Windows服务,该服务利用Windows事件日志来记录其活动.我已经创建了安装项目来安装此Windows服务.当我尝试安装此Windows服务时.安装程序已启动,但因
失败

Hi all,

I''m developing a windows service that makes use of windows event log to record its activities. I have created the setup project to install this windows service. When I tried to install this windows service. the installer started but failed with

error 1001: Source <servicename> already exist.



我怀疑事件日志会导致此问题,因此我将其从Windows服务中删除,该服务将安装并运行而没有任何问题..但是我想记录服务活动,因此我将事件日志放回Windows服务中,看看我的事件查看器,然后猜测一下:有一个事件日志文件具有相同的日志名称和来源.
所以这就是我的工作:
我使用EventLog.DeleteEventSource(source)EventLog.Delete(logName)删除现有的日志文件和源.

我再次查看事件查看器,但找不到那个特定的日志文件.

然后我尝试安装Windows服务,安装程序启动,这次没有失败..

但是,出现了新问题.当我尝试启动该服务时,它将立即停止.看来,事件日志再次是引起问题的原因,因为当我从Windows服务中取出事件日志控件时,我没有遇到这个问题.

对事件日志控件使用不同的logName和源实际上可以解决问题..但是...

我不想使用不同的logName和来源....如果任何人都知道如何在不更改logName和来源的情况下解决此问题,请与我分享..我真的很感激..

最好的问候,
Paulus



I suspect that event log is causing this problem, so i removed it from windows service and the service will install and run without any problem.. But i want to log the service activities, so I put the event log back into the windows service, look to my event viewer, and guess what: There is an event log file with the same log name and source..

So this is what i do:
I use EventLog.DeleteEventSource(source) and EventLog.Delete(logName) to delete the existing log file and source.

Again I look into event viewer and I couldn''t find that particular log file.

Then I tried to install the windows service, the installer started and this time it didn''t fail..

However... new problem comes out.. When I tried to start the service, it will immediately stop. It seems that, again, the event log is the one causing problem since I didn''t face this problem when i took out the event log control from my windows service..

Using different logName and source for the event log control will actually solve the problem.. But...

I do not want to use different logName and source....... If anyone knows how to solve this problem without changing the logName and source, please share with me.. I really appreciate it..

Best Regards,
Paulus

推荐答案

自定义事件源的安装和卸载逻辑非常复杂,因此在某些情况下很容易出错.不查看代码就很难找出问题所在.而且您很难创建一个适合您问题中的帖子而又能表明问题的简短代码示例.让我们先尝试另一种方法.

我使用一些代码来构建软件产品的每个不同应用程序的事件日志记录,并共享了一个小的包装程序,演示了正确的技术.尤其显示了如何设置和清理.
请在这里查看我过去的答案:

如何在文件夹下创建事件日志 [ ^ ].

我希望它可以帮助您了解如何正确进行操作.如果仍然不能解决问题,则需要做好上面提到的代码示例.如果您有一些异常,请不要忘记将其转储(在文件中),输出Exception.Stack和所有内部异常(递归)并在源代码中标记所有相关行.顺便说一句,当您进行所有这些准备工作时,您会清楚地自己理解问题并能够解决.

—SA
Installation and uninstallation of a custom event source has a pretty complex logic, so it is quite easy to make a mistake is some scenarios. It''s hard to find out what was your problem without looking at your code; and it would be difficult for you to create a short code sample suitable for the post in your question yet manifesting the problem. Let''s try another way first.

I use some code to structure event logging per different application of the software product and shared a small wrapper which demonstrates right techniques. In particular, is shows how to setup and clean-up.
Please see my past answer here:

How to create event log under a folder[^].

I hope it will help you to see how to do it right. If you still cannot solve a problem, you will need to do a good for making the code sample I mentioned above. If you have some exception, don''t forget to dump it (in file), output Exception.Stack and all inner exceptions (recursively) and mark all relevant lines in your source code. By the way, chances are, when you do all these preparations you will clearly understand your problem by yourself and will be able to solve it.

—SA


阅读.

错误1001:来源"ServiceName"已经存在存在于本地计算机上 [ ^ ]
Read this.

Error 1001: Source ''ServiceName'' already exists on local computer[^]


这篇关于Windows服务启动,然后停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆