I have a windows service that generates logs as it does some execution. I also do console.writeline
c开发者_运维问答all 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
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.
I think you'll struggle to attach a console to an existing service. Two easy options
- write to the windows application log
- write to a text file, which you can then open with wintail or similar
Re your update - number 2 would be best then.
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.
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...
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.
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!
Or open the file with http://www.log-expert.de/ and tail away. You can even make it colorful!
精彩评论