We have a C# service that is deployed to a remote customer system. The application writes a substantial amount of "diagnostic" information to the console (i.e. Console.WriteLine()). The service isn't "doing what it should." How can we capture the console output from the service in another application?
A WinForm version the application can be loaded at the customer location. It, unfortunately, functions correctly.
Update:
We are able to change the change the service, but would prefer not to make major changes at this time.
We are also logging to MSMQ, but only for "important" events. This service does interact with MSMQ for its normal operations. Or, at least, it should. The service doesn't seem to be pulling items from MSMQ when the WinForm version does. So, writing the messages that are going to the console could be problematic.
Here is how I viewed the console output of a service running under Windows 7. This might help if you are absolutely unable to modify the source code of the service to log to a file.
Run services.msc and edit the properties of the service. On the "Log On" tab, check the "Allow service to interact with desktop"
Use registry editor to modify the ImagePath of your service: Go to HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\ [your service name] and edit ImagePath. Append
cmd.exe /c
to the beginning of the ImagePath string. So if your original ImagePath isc:\myService\myservice.exe
your new ImagePath should becmd.exe /c c:\myService\myservice.exe
.Start your service. You should get a popup window titled "Interactive Services Detection". Select "View the message". Your screen should switch contexts and display the console window. When finished, click the "Return now" button.
When finished debugging, modify ImagePath back to its original value. Then uncheck the "Allow service to interact with desktop" checkbox in the service properties and restart your service.
Warning: I've only done this with one service and it worked for me. I do not know if it will work for any service or if it will cause any unexpected results so I strongly suggest you only do this in a non-production environment.