C# Windows Service keep creating logs - c#

I have a problem on my windows service that keeps writing the same logs, anyone knows the solution for the service to not keep creating same logs like this? All that aside, my service is still running smoothly but it just keeps on creating logs files. If I open the log files, the timestamp for each log is for example 8:34:42 AM

Related

log4net and event logging suddenly stopped working on Windows service

I have a Windows service (c#, .net v4.5.2) that runs daily and is supposed to log errors to the Windows Event log (via System.Diagnostics) and errors plus progress information to the database (via log4net). Log4net is set to write "INFO" level.
Both logging mechanisms were working fine last time I looked, but last night the Windows service failed. I went to the d/b and event log and found that it hasn't written to either since 20th June, until it logged the automatic restart (to both logs) after it crashed last night.
Platform is a Windows 2012R2 VM in Azure. The service takes change-tracked SQL updates from a slave database, applies them to the master database, backs up the master and restores it over the slave, the log4net log is on the master. It's all been running fine, it just gave up logging.
Can anyone explain why it might have stopped logging to both log4net and the Windows event log?
The application server, domain controller and database server were all rebooted at the same time on the day log4net stopped logging. The likely cause therefore is that when the application server started up and the Windows service started, log4net was unable to connect to the database and shut down.
(Absence of Windows events probably a red herring - since the service was otherwise running happily without any errors, there just wasn't anything for it to write to Windows events.)

How to start my Application on Server startup

I have a Windows Forms Application which runs on a server. I need this Application to always start automatically. Even if the Server just gets restartet and nobody logs into it the Application should run.
So the solutions with Registry don´t work here. I than read into Windows Services but it seems like I can´t start a WinForm Application with it.
Does anyone have an idea how I can achieve this automatic Start on Server startup?
The way we do things like that is that we create a Windows Service which runs without the need to have anyone logged in, and then if there is a need we have a separate GUI application (WinForms in your case) which interacts with the service, when needed.
The communication between the GUI application and the Windows Service is usually done by means of named pipes, but if you can get away with something simpler, like the GUI application saving a configuration file for the service to pick up, you might make it easier for you.

Winform inside a windows service in C# - Possible?

I am writing a windows service to process emails on a daily basis. This service includes a App.Config file, which has several parameters for the service to work accordingly.
Every time, the admin user has to go and change / add / delete the pair inside the section using a text editor.
I am planning to include a windows form to load all the pair from the section and thinking of doing any modification through the form.
All I would like to know is whether it's possible to have a winform inside a windows service and open it when ever the configuration needs to be changed? I know we can have a seperated windows application and load the App.Config file of the windows service. I just want to avoid having a seperate app for this.
If you have done something very similar to this, please share your thoughts!
Regards,
Sriram
That sounds like a security issue if nothing else.
A Windows service runs in a different context and account and cannot interact with the desktop unless specifically allowed when installing the service. This is not enough of course so you'd also have to have the service running under the same account that is running the desktop - this in itself is really bad design and not something I would recommend.
You could also have the service executable decide what to do during launch, a common pattern is to have it spawn as a console application when debugging to simplify development. But then you'd have to stop the service and launch the service executable manually interactively to get the UI behaviour.
In any way, a separate configuration tool is the way to go.

File System watcher in Windows Service or Console Application?

I am implementing a file system watcher, my requirement is to watch for a given local folder on a machine and then do a small task (for example open a certain page in web browser). The file(s) in the given directory would be generated randomly sometimes every two hours or four etc. This tool should be automated in the sense that a user does not have to start it. So my question is, Should I implement this in a windows service which always will be running or in a console application.Preference is to do it in a console application but then it would need to started by a user right? Please advice
You can automatically call any type of application (Console, Windows, etc.). What it gets down to with a Windows Service is whether you want it to be running before anyone logs in.
Only a Windows service runs while no one is logged in. A console application (while it can be set to run on login) must have someone log in in order to run.

Logging from a Windows Service to another machine

I wrote one windows service locally..Now i will going to deploy it on server...My requirement is that i want to write start & stop timing of service on my local machine.
so i did that locally when my service is on my local machine..
But when it will get deployed on server so how will i write that start & end time to that text file which is on my local machine...?
If I'm correct in interpreting your question, then you're deploying the service to MachineA and your PC is MachineB. You want to have the service running on MachineA write to a log file on MachineB?
If this is the case, it's a simple matter to create a share on MachineB and have the service write to a file on that share, rather than a local file. So, rather than writing to C:\Log\MyLogFile.log, have the service write to \\MachineB\Log\MyLogFile.log.
One thing to consider is the fact that this means that your service won't be able to log unless your PC is running. You'll need to ensure that your code fails gracefully if this occurs, rather than hanging or crashing.

Categories

Resources