473,320 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Running as a service or as an application.

We wrote some code (utility stuff) that is intended to run as part of
either a windows service, a console app or a windows app. What I'd
like to do is when it is running as a service have it log exceptions
to the event log, when as a console app, write them to the Console,
and when running as a windows app. raise an event.

Anybody have any ideas other than setting some flag values in the
launching application. We can't do that because we don't control the
app that uses these utilities.

Oct 17 '07 #1
2 1749
I would have your library take a trace provider (or something that you
have provided in an abstract form, like an interface or abstract class) and
then just write to that trace provider. This way, it is the responsibility
of the app calling you to set up where the logging goes to, not you.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<to*******@eds.comwrote in message
news:11**********************@t8g2000prg.googlegro ups.com...
We wrote some code (utility stuff) that is intended to run as part of
either a windows service, a console app or a windows app. What I'd
like to do is when it is running as a service have it log exceptions
to the event log, when as a console app, write them to the Console,
and when running as a windows app. raise an event.

Anybody have any ideas other than setting some flag values in the
launching application. We can't do that because we don't control the
app that uses these utilities.

Oct 17 '07 #2
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.

Oct 17 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: BK | last post by:
Can someone point me to a code sample that illustrates executing long running tasks (asynchronous) from a web application in ASP.NET? I assume that Web Services might come into play at some point,...
7
by: Ross Presser | last post by:
OK, I've been researching this problem and can't find a definitive answer yet. The situation is one that seems to have come up a few times to different folks. I am writing an application that...
0
by: Martijn Remmen | last post by:
I have developed a service which exposes a COM object. This service is running perfect on Windows 2000 Server and Windows 2000 Professional under the SYSTEM account. When the service is...
0
by: Mr Bounce | last post by:
Hi, Probably well worn ground, this, but im stumped and need some help, if you could: I'm trying to write some code for a windows service that needs to run in the background polling a server...
0
by: Claire | last post by:
Ive written a threaded service application, realtime monitoring across a network, heavy processor usage. Probably will be running on a dedicated pc When it's running as an application it's nippy....
3
by: jliusolar | last post by:
Hi I am trying to figure out why an application get this error when I am trying to open the application's asmx file from localhost. I don't have indexing service running(it set as manual and not...
4
by: news.citenet.net | last post by:
I keep getting the following error message after my web site running 2 or 3 days I share one folder with about 200 domain names Any one can help? ...
4
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
4
by: Max2006 | last post by:
Hi, I am developing a web application on windows XP. A page within my application needs to access to SSRS running on the same machine. Once the web application tries to consume the SSRS web...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.