[英]How can I get the name of my Windows Service at runtime?
I have a new Windows Service I'm making in C# 4.0. 我有一个新的Windows服务,我在C#4.0。
I'm trying to drop in some event logging code I wrote a while ago which is in a seperate class. 我试图删除我刚才写的一些事件记录代码,这是在一个单独的类中。
I want to set the event source to the name of the Windows Service without having to change the code next time I drop it into a service. 我想将事件源设置为Windows服务的名称,而不必在下次将其放入服务时更改代码。
I'm looking for something like this: 我在寻找这样的东西:
String source = Application.Name
But I can't seem to find what I'm after anywhere. 但我似乎无法找到我追求的东西。
Any takers? 任何接受者?
如果代码在服务应用程序中,您可以这样做
String source = this.ServiceName;
You will not be able to call a static property. 您将无法调用静态属性。 Unless you write your own static wrapper to get the value of the ServiceName property of your ServiceBase derived class.
除非您编写自己的静态包装器以获取ServiceBase派生类的ServiceName属性的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.