473,666 Members | 2,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1773
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.co m

<to*******@eds. comwrote in message
news:11******** **************@ t8g2000prg.goog legroups.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.c om!

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.WriteLi ne(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
2838
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, but I'm not sure how to get started. For example, I have an application that, upon a user initiating through a button or link click, will go out and generate a bunch of files (this could take several minutes). This will happen in batches, so I...
7
6923
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 will function as a windows service and will also present a GUI to the user. I don't want "Interact with desktop"; I want the same exe to run as a normal non-interactive service when started properly by the service control manager, or instead to run...
0
565
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 installed on Windows 2003 Server, the application works well, and the COM object can be called just as it's meant to be. The service is however running under the IWAM account (I know strange account to run a service). However, after a while (from...
0
1518
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 for commands. Certain commands require the service to interact with the application running on the active desktop, currently just to either shut it down or start it.
0
1122
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. As a service it's running slowly as a snail. I'm running it on an XP pro machine with performance priority set to background services. What else can I do to speed it up? CPU monitor in task manager shows it's only getting 0-11% processor time...
3
2201
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 started). I also created an .aspx file to do testing The .aspx file opens fine in other directory from IE. As long as I put it in the application's directory, set a virtual directory trying to open it, it also gives me the following error. I don't...
4
5235
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
4175
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 check to see if the status is in stopped or running mode. But that doesn't tell me if it is actually running. I need to know this so that if it happens I can programmatically start the same service on another machine.
4
2799
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 services, I receive the following error: System.Web.Services.Protocols.SoapException: The permissions granted to user DEV1\ASPNET' are insufficient for performing this operation. --->...
0
8454
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8878
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8785
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7389
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5671
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4200
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.