开发者

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.

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.

I'm looking for something like this:

String source = Appl开发者_如何转开发ication.Name

But I can't seem to find what I'm after anywhere.

Any takers?


If the code is within the service application, you could do

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜