Colleagues,
I'm trying to test and debug a Windows Service program.
The Program is supposed to report files creation/modification/deletion of XML files by writing a report line to a LOG file.
(If it's of any significance, that same program made as WinForms actually works. I copy-pasted the relevant parts - OnFileChanged(), etc. - from that WinForms app to the WinService app.)
To test and debug my WinService app, I followed the instructions on this page to the letter:
- Created program, made an EXE (in the \bin\Debug subdir),
- Installed it as a Service,
- Started service,
- In the VS IDE (run as Admin), attached it to the service,
- Did what this service is supposed to report (deleted one XML in the monitored directory) - no reaction!
- I stopped and [re]started my service (several times) - zilch/nada/bubkis/ (don't wanna slip to profanities... )
Moreover, even program's performance LOG file was not created!
I've been struggling to find out the cause of this behavior for 3 workdays now - no success.
Here's the code of the main class:
Here's the code in the OnStart() proc:
As I've already said, this LOG file is not being created. And the questions are:
1. Is the OnStart() the right place for creating this LOG file?
If not, then
2. Where, in my program, am I to place the code for creation of this LOG file?
TIA!
Regards,
Ilya
I'm trying to test and debug a Windows Service program.
The Program is supposed to report files creation/modification/deletion of XML files by writing a report line to a LOG file.
(If it's of any significance, that same program made as WinForms actually works. I copy-pasted the relevant parts - OnFileChanged(), etc. - from that WinForms app to the WinService app.)
To test and debug my WinService app, I followed the instructions on this page to the letter:
- Created program, made an EXE (in the \bin\Debug subdir),
- Installed it as a Service,
- Started service,
- In the VS IDE (run as Admin), attached it to the service,
- Did what this service is supposed to report (deleted one XML in the monitored directory) - no reaction!
- I stopped and [re]started my service (several times) - zilch/nada/bubkis/ (don't wanna slip to profanities... )
Moreover, even program's performance LOG file was not created!
I've been struggling to find out the cause of this behavior for 3 workdays now - no success.
Here's the code of the main class:
Code:
'====================================================================================================================================
Public Class FileMonitorService
'====================================================================================================================================
Inherits ServiceBase
Public CommonSubs As CommonSubs
Public fsWatch As FileSystemWatcher
Public gsWorkDir As String = ""
Public gaWorkSubDirs() As String
Public gsStartDir = CommonSubs.AddBackSlash((Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)).Replace("\bin\Debug", "\"))
Public gsAppName = (System.Reflection.Assembly.GetExecutingAssembly().GetName().Name).ToUpper()
Public gsLogFile = gsStartDir + gsAppName + ".LOG"
Here's the code in the OnStart() proc:
Code:
'====================================================================================================================================
Protected Overrides Sub OnStart(ByVal args() As String)
'====================================================================================================================================
' Start or continue the LOG file
Dim lsLogStr As String = CommonSubs.Replicate("=", 80) + vbCrLf + String.Format(Now, "yyyy-MM-dd HH:mm:ss") + _
": Service started" + vbCrLf + CommonSubs.Replicate("=", 80) + vbCrLf
CommonSubs.Write2LogFile(gsLogFile, lsLogStr)
As I've already said, this LOG file is not being created. And the questions are:
1. Is the OnStart() the right place for creating this LOG file?
If not, then
2. Where, in my program, am I to place the code for creation of this LOG file?
TIA!
Regards,
Ilya