开发者

ServiceBase.OnShutdown and event logs in Windows .Net 3.5

开发者 https://www.devze.com 2023-01-06 19:36 出处:网络
I\'ve written a custom service that overrides ServiceBase.OnShutdown(). Unfortunately, when I log to the event log, nothing is written.

I've written a custom service that overrides ServiceBase.OnShutdown(). Unfortunately, when I log to the event log, nothing is written. My guess is that the Windows event log was shut down befo开发者_C百科re my service. Is there a way to order service shutdown so that my servce shuts down before the event logger? I don't want to have to write out to a file. Pl. advise. Thanks.


You could try to setup a dependency where your service depends on the Event logger, this is mostly done to make them load in the correct order but I assume that might make sure that your service always was stopped first as well.
As can be seen in this Technet article, you'd need to change the DependOnService value either using the Sc.exe tool or the ChangeServiceConfig API.


There is a way, but it is more or less a Reflection-Hack. I added my solution to an other post: Here

Hope I could help.

0

精彩评论

暂无评论...
验证码 换一张
取 消