1

I am using Windows Service using C#.I want an output in Console say Console.WriteLine("Hello").I am not able to get that whereas I am able to successfully write it make an eventLog Entry.

  eventLog1.WriteEntry("In OnStart");
        try
        {
            Console.WriteLine("Hello");         
            DBSyncHandler sync = new DBSyncHandler();
            sync.startSync();

        }

Say therefore I am not able to check whether it is writing to Console and executing below mentioned code.

2
  • If you're writing a service you don't have a console, use the event log instead. Commented Sep 21, 2011 at 10:46
  • Hi Jon .Thanks.But how will I come to know whether the Code has been executed...Do you mena I need to write it to EventLog at each step where earlier Console was.Say In DbSyncHandler Class when creating an instance ,there are stages where console display is used.Do you mean I need to use EventLog there to check how much code is been executed in DBSyncHandler. Commented Sep 21, 2011 at 11:03

3 Answers 3

5

You probably mean Debug.WriteLine don't you ? If so, use the sysinternals debug viewer to watch every debug message send by any application (including services)

edit : Step by step

  1. Replace the Console.WriteLine by Debug.WriteLine
  2. Download debug viewer
  3. Run debug viewer and start your service
  4. Debug Viewer will show you every message send to Debug. (you can filter to only see what's interresting for you)
  5. Voila !
Sign up to request clarification or add additional context in comments.

1 Comment

Can you elaborate little more. I need to know how ` DBSyncHandler sync = new DBSyncHandler(); sync.startSync(); is getting executed or not.
0

You have no Console window available within a windows service; the option I would use would be to use a logging framework (such as log4net) to output the statements to a log file

Comments

0

In order to see Console output in a Windows Service, you need to set up your service with "Allow the service to interact with Desktop"

Control Panel --> Admin Tools --> Services --> select yours --> (right-click) Properties --> Logon Tab --> Tick "Allow service to interact with Desktop"

3 Comments

@developer82 and then any Console.WriteLine statements that you have on your service will be displayed on the typical DOS prompt.
How do I attach the DOS prompt to the service? Thanks
I too need an answer to this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.