Services..

  • Thread starter Thread starter Chizl
  • Start date Start date
Willy Denoyette said:
The logs I posted are from YOUR project, only change I made was specifying
an absolute path for the log file, following is why I did.
The log file of this *Service* is NOT in the exe path, the log file you
see in the exe path is the one created when running installutil.
You are writing to a file that does not specify a path ( a relative path),
that means you are writing your logfile in the home of the application
that started the service. Services are started by the SCM which has it's
home path set to Windows\system32, your service will try to create/write
to windows\system32.
If your service runs as LocalSystem, you should find the log file in
Windows\system32 (but you should never do this), if it runs as
LocalService, you won't see a logfile at all, this account cannot write to
the Windows\system32, and you fail to check the result of the logging.

What's wrong writing to his own System Application Eventlog?
 
Mr. Arnold said:
What's wrong writing to his own System Application Eventlog?



Nothing, but this is not what the OP is doing, he's writing to a regular
file not to the Eventlog.

Willy.
 
Chizl said:
When I add an installer of which MS tells me I have to do, it creates the
ProjectInstaller.cs.. If there is a better way, please elaborate.. I
just want this to run as a service, I don't really care how at this point.

As you see in the two examples, there is no talk about the
Projectinstall.cs. You don't need it. You simply create your Windows Service
project without the ProjectInstaller.cs, build the exe, and you use
InstallUtil to install the service.exe.

Now, if you have to use a ProjectInstaller.cs, then by all means use it. But
it doesn't mean that you have to use it.

http://www.aspfree.com/c/a/C-Sharp/Creating-a-Windows-Service-with-C-Sharp-introduction/
http://www.vbdotnetheaven.com/UploadFile/mahesh/Winservvb11172005233242PM/Winservvb.aspx
 
Willy Denoyette said:
Nothing, but this is not what the OP is doing, he's writing to a regular
file not to the Eventlog.

He should dump it or use the Application Block to write to a log file.
 
Mr. Arnold said:
He should dump it or use the Application Block to write to a log file.

When I stress test, I'm writing over 80,000 to the log.. This is a web
server that logs everything. EventLog is not meant for that.

I see what your saying about it's not a relative path.. I've also noticed,
I'm using / instead of \ so that I can compile this under Mono for
CrossPlatform development, but seems as a service, it's having a problem
with it..

I added: System.Diagnostics.Debugger.Launch(); so I could start walking
through the service and there is all kinds of path issues I have to resolve
so that it will run as a service..

What is the best way to get Local Path? I'm using:
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
However, that returns file:// in front of it.. Is there a faster or better
way?
 
Mr. Arnold said:
As you see in the two examples, there is no talk about the
Projectinstall.cs. You don't need it. You simply create your Windows
Service project without the ProjectInstaller.cs, build the exe, and you
use InstallUtil to install the service.exe.

Now, if you have to use a ProjectInstaller.cs, then by all means use it.
But it doesn't mean that you have to use it.

http://www.aspfree.com/c/a/C-Sharp/Creating-a-Windows-Service-with-C-Sharp-introduction/
http://www.vbdotnetheaven.com/UploadFile/mahesh/Winservvb11172005233242PM/Winservvb.aspx

Thanks, I appreciate all the help, thus far.. Banging my head on the
desk, since this is the thing out of all the stuff I've done that doesn't
want to work..
 
I have a SERVICE!!! WOOT!! It had to do with all the path issues, which
finding the debug call while running as a service helped a lot.. I want to
thank both Willy and Mr. Arnald.. You guys rock..

But with all this, I think that kind of sucks.. Running as a service
doesn't use the same path methods as an application. It's almost as if two
different departments wrote C# at MS.

Thanks again..
 
Chizl said:
I have a SERVICE!!! WOOT!! It had to do with all the path issues, which
finding the debug call while running as a service helped a lot.. I want to
thank both Willy and Mr. Arnald.. You guys rock..

But with all this, I think that kind of sucks.. Running as a service
doesn't use the same path methods as an application. It's almost as if
two different departments wrote C# at MS.

This has absolutely nothing to do with C#, this is how Windows and Windows
Services work, the implementation language is not relevant. Window Services
must adhere to the rules imposed by the SCM, who's the parent process of all
Services. And as it goes with all processes in windows, your Service
inherits it's environment from it's parent (the SCM) which is not the same
as the environment of a process launched from a command shell or the
interactive shell (explorer for instance). Note also that services do not
have a profile loaded, cannot (by default) access the visible desktop, nor
do they run in the same security context as an interactive logon session
(which may or may not be present). Services are background tasks (similar to
daemons on **ix), they may run in their own process, or they may share a
process with other services, mostly started at boot time and running till
shutdown, they have a dedicated task to accomplish, and because of their
nature, they must be as robust as possible (especially when they share a
process with others).

Willy.
 
Chizl said:
When I stress test, I'm writing over 80,000 to the log.. This is a web
server that logs everything. EventLog is not meant for that.

Why reinvent the wheel? There is a whole section about using the
Application Blocks' logging abilities.

I see what your saying about it's not a relative path.. I've also
noticed, I'm using / instead of \ so that I can compile this under Mono
for CrossPlatform development, but seems as a service, it's having a
problem with it..

I added: System.Diagnostics.Debugger.Launch(); so I could start walking
through the service and there is all kinds of path issues I have to
resolve so that it will run as a service..

What is the best way to get Local Path? I'm using:
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
However, that returns file:// in front of it.. Is there a faster or
better

Well, I think that's what I use. So you make a String Function that returns
what you want out of the string path. :)
 
Mr. Arnold said:
Well, I think that's what I use. So you make a String Function that
returns what you want out of the string path. :)

What I ended up doing is creating a static property that stores this info in
a var, so I'm not executing the same IO.Path each time..

public static String AppPath
{
get { return m_szAppPath; }
set { m_szAppPath = value; }
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top