How to log Console.WriteLine output

How to log Console.WriteLine output

Post by RGFtaXIgRG » Mon, 07 Jul 2008 03:26:00


I'm new to VS.NET 2008 and WCF development (.NET 3.5).
I'm developing a WebService prototype. I would like to use Console.WriteLine
(or similar) to log some information I need for future development /
troubleshooting. Unfortunately I didn't figure out the way to log the output
to a file.

I spent few hours studying and trying out the web.config ->
system.diagnostics, but I figured out it is not meant to be used for what I'm
looking for - maybe I'm mislead and I just don't know how to use it.
I also found Apache Log4Net that is supposed to address my needs; however, I
would like to avoid using a 3rd party library just for simple logging - there
should be a simple way to do it in .NET.

Can someone point me to the solution? :)

Damir Dezeljin

How to log Console.WriteLine output

Post by Mr. Arnol » Mon, 07 Jul 2008 16:11:57

You can just use the eventlog, by creating it on the fly and then using it.
The eventlog which should be created as an Application Eventlog on a NT
based O/S can be viewed with the Event viewer on another machine across the
LAN. I have done this with Console and NT Service application, and I don't
see why you couldn't do it with a WCF solution.

The example is in VB.Net but you can do the same thing in C#.Net


How to log Console.WriteLine output

Post by RGFtaXIgRG » Thu, 10 Jul 2008 17:48:01

Thanks Arnold.

Anyway ... EventLogging isn't really what I'm looking for. Well, it can be
used as a first solution; however, I'm still looking for a solution to easily
log to files like e.g. I do by using log4j with Axis2 web services.

Any other hint? Or at least can someone tell me if it is at least possible
do it in .NET C#?


How to log Console.WriteLine output

Post by Mr. Arnol » Sat, 12 Jul 2008 05:57:29

Doesn't Application Blocks for .Net have a logging functionality, use Google
look it up?