Hello,
to*******@eds.com!
First of all there must be one (for all hosts) logging interface. Then 3
separate implementations of that logging interface.
Say
interface ILog
{
void Write(string msg);
}
ConsoleLogger : ILog
{
public void Write(string msg)
{ Console.WriteLine(msg); }
}
and other implementations for service and windows app.
Then there must be a factory class that will detect if app runs as a service
or console, or WinForms app and that's the hardest part here :)
Here is what I can suggest (it is not 100% logic):
- to detect if under WinForms - check via Reflection if there is access to
Application class
- to detect if under WindowsService - check via Reflection if there is
ServiceBase class there
- if neither is correct then code is working as a Console App
Also you have to consider the possibility of running under ASP.NET
application (the same Application class but from different namespace ).
HTH
--
With best regards, Vadym Stetsiak.
Blog:
http://vadmyst.blogspot.com
You wrote on Wed, 17 Oct 2007 07:06:32 -0700:
tsWe wrote some code (utility stuff) that is intended to run as part
tsof either a windows service, a console app or a windows app. What
tsI'd like to do is when it is running as a service have it log
tsexceptions to the event log, when as a console app, write them to
tsthe Console, and when running as a windows app. raise an event.
tsAnybody have any ideas other than setting some flag values in the
tslaunching application. We can't do that because we don't control
tsthe app that uses these utilities.