什么是最可靠的方法来创建一个净服务在安装过程中自定义事件日志和事件源事件、自定义、方法来、创建一个

2023-09-04 01:30:38 作者:爱情特么该拿去喂狗

我有困难可靠地创建/我的。NET的Windows服务的安装过程中删除事件源。

I am having difficulty reliably creating / removing event sources during the installation of my .Net Windows Service.

下面是从我ProjectInstaller类code:

Here is the code from my ProjectInstaller class:

// Create Process Installer
ServiceProcessInstaller spi = new ServiceProcessInstaller();
spi.Account = ServiceAccount.LocalSystem;

// Create Service
ServiceInstaller si = new ServiceInstaller();
si.ServiceName = Facade.GetServiceName();
si.Description = "Processes ...";
si.DisplayName = "Auto Checkout";
si.StartType = ServiceStartMode.Automatic;

// Remove Event Source if already there
if (EventLog.SourceExists("AutoCheckout"))
    EventLog.DeleteEventSource("AutoCheckout");

// Create Event Source and Event Log     
EventLogInstaller log = new EventLogInstaller();
log.Source = "AutoCheckout";
log.Log = "AutoCheckoutLog";

Installers.AddRange(new Installer[] { spi, si, log });

引用刚刚返回的字符串日志的名称,服务等门面的方法。

The facade methods referenced just return the strings for the name of the log, service, etc.

这code工作的大部分时间,但最近安装后,我开始我的日志条目显示在应用程序日志,而不是自定义日志了。而下面的错误日志中还有:

This code works most of the time, but recently after installing I started getting my log entries showing up in the Application Log instead of the custom log. And the following errors are in the log as well:

源(AutoCheckout)事件ID(0)的描述无法找到。本地计算机可能没有必要的注册信息或消息DLL文件来从远程计算机显示消息。您可以使用/ AUXSOURCE =标识来检索词描述;查看帮助和支持的详细信息。

The description for Event ID ( 0 ) in Source ( AutoCheckout ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details.

由于某种原因,要么是不正确的卸载过程中删除源或安装过程中它没有创造它。

For some reason it either isn't properly removing the source during the uninstall or it isn't creating it during the install.

任何帮助,最佳实践这里是AP preciated。

Any help with best practices here is appreciated.

谢谢!

另外,这里是我如何写例外日志的示例:

In addition, here is a sample of how I am writing exceptions to the log:

// Write to Log
EventLog.WriteEntry(Facade.GetEventLogSource(), errorDetails, EventLogEntryType.Error, 99);

关于stephbu的回答:推荐路径是安装脚本和installutil,或Windows安装程序

Regarding stephbu's answer: The recommended path is an installer script and installutil, or a Windows Setup routine.

我使用的是安装项目,它执行服务的安装和设置了日志。无论我用的是installutil.exe或Windows安装项目,我相信他们都呼吁同ProjectInstaller类我在上面。

I am using a Setup Project, which performs the installation of the service and sets up the log. Whether I use the installutil.exe or the windows setup project I believe they both call the same ProjectInstaller class I show above.

我怎么看我的测试机的状态可能会导致错误如果日志没有真正删除,直到重新启动。我会尝试更多,看看是否能解决问题。

I see how the state of my test machine could be causing the error if the log isn't truly removed until rebooting. I will experiment more to see if that solves the issue.

编辑: 我感兴趣的肯定火的方式来注册服务的安装过程中的源和日志的名称。因此,如果该服务有previously都安装完毕,将在后续的安装取出源,或重用源。

I'm interested in a sure fire way to register the source and the log name during the installation of the service. So if the service had previously been installed, it would remove the source, or reuse the source during subsequent installations.

我还没有有机会学习WiX的尝试这条道路。

I haven't yet had an opportunity to learn WiX to try that route.

推荐答案

最好的建议是不使用Visual Studio中的安装项目。它有非常严格的限制。 我有很好的效果与维克斯

The best recommendation would be to not use the Setup Project in Visual Studio. It has very severe limitations. I had very good results with WiX