Reputation: 3601
I have a windows service that generates logs as it does some execution. I also do console.writeline
call for every log message I write into the log file. But since its a windows service the console.write line is not visible.
I want to write a C# console application program that can attach to my service (already running) and it could just show all console.writeline
messages that the process (my windows service) is generating.
updated: The volume of log is very frequent ( 50 messages every minute) , I would prefer not want to crowd windows event log for this. Using a cosole window helps to look at logs and exit on convenience
Upvotes: 6
Views: 2791
Reputation: 3601
I used cygwin to tail on the log file thats created by log4net this seems to do the trick for me.
Thanks for all the help!
Upvotes: 1
Reputation: 10927
Or open the file with http://www.log-expert.de/ and tail away. You can even make it colorful!
Upvotes: 0
Reputation: 8174
Send data via UDP and make a simple program to show the data.
You warrant and asynchronous operation and can even send to another host.
Upvotes: 1
Reputation: 3518
I think you'll struggle to attach a console to an existing service. Two easy options
Re your update - number 2 would be best then.
Upvotes: 5
Reputation: 13092
I would suggest you to log messages to Windows Event Viewer, if don't have burning desire to show them on console window. This link would help you...
Upvotes: 1
Reputation: 57919
You can make the service interactive, in which case you'll see the console window, but you'll always see it, and I think if you close it, you'll stop the service.
Alternatively, make your console monitor read updates out of the log file at a reasonable interval instead of trying to get into the service process directly.
Upvotes: 1
Reputation: 176169
Displaying a window from a service is not a good idea as you would have to find out the "correct" session (Windows allows several users to be logged on) and also requires the service to have access to the user's desktop.
Instead, it is probably easiest to change the Console.WriteLine
calls into Trace.WriteLine
. Then you can attach to these trace messages, e.g. by using SysIntenal's DebugView.
Upvotes: 6