Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# Windows Service Console.Writeln

I wrote, installed, and successfully started a Windows Service in c# that does nothing :) Initially I just want echo stuff to the console, db queries the service makes etc. I used the OnStart in my service, but from a cmd prompt when I do a net start "My Service" where do these messages show up?

I'm open to better ways. I'm new to this and feeling my way through it step by step by echoing back to the console my progress. Should I echo to the event log instead? How do I do that?(I know, I know, google it)

 protected override void OnStart(string[] args)
    {
        base.OnStart(args);
        Console.WriteLine("Sham-Wow!");
    }
like image 978
rd42 Avatar asked Feb 11 '26 22:02

rd42


2 Answers

You cannot write the console from a Windows Service.

I recommend you using any logging utility, such as log4net.

The second alternative is writing to the Event Log (System.Diagnostics.EventLog)

like image 73
Daniel Peñalba Avatar answered Feb 15 '26 13:02

Daniel Peñalba


Try System.Diagnostics.Trace.WriteLine and you will see your messages in Output window of Visual Studio or with dbgview utility.

like image 33
Denis Palnitsky Avatar answered Feb 15 '26 12:02

Denis Palnitsky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!