Reputation: 2398
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 = Application.Name
But I can't seem to find what I'm after anywhere.
Any takers?
Upvotes: 3
Views: 3533
Reputation: 593
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.
Upvotes: 1
Reputation: 4711
If the code is within the service application, you could do
String source = this.ServiceName;
Upvotes: 4