locked
C# console log file RRS feed

  • Question

  • I have a C# 2008 console application where all the output is displayed in DOS popup windows instead of being written to a log file.
    Thus can you tell me what I can do to have all messages in this console application appear in a log file instead of these dos pop windows? Can you show me in code how to accomplish this goal?
    Wednesday, October 17, 2012 6:06 PM

Answers

All replies

  • Please check the following URL

    http://msdn.microsoft.com/en-us/library/system.console.seterror.aspx


    With Thanks and Regards
    Sambath Raj.C
    click "Proposed As Answer by" if this post solves your problem or "Vote As Helpful" if a post has been useful to you
    Happy Programming!

    Wednesday, October 17, 2012 6:31 PM
  • I think you need to look at writing text files possibly using a stream writer.

    The code could be based on something like this:

    using (var wrt = new StreamWriter(fileName) {
       wrtr.WriteLine(logMsg);
    }

    You need to provide a value for the file name and the logMsg.Also the StreamWriter constructor has other parameters to set whether open for read or write and whether to append or create new file.

    That's the basics but not knowing the code there may be other things to consider.


    Regards David R
    ---------------------------------------------------------------
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
    Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
    Every program eventually becomes rococo, and then rubble. - Alan Perlis
    The only valid measurement of code quality: WTFs/minute.

    • Proposed as answer by JMCF125 Wednesday, October 17, 2012 6:48 PM
    Wednesday, October 17, 2012 6:37 PM
  • I want both good and bad messages.
    Wednesday, October 17, 2012 6:37 PM
  • Sambath's solution was nice, but I'm using Log4Net library for 90% of my applications.

    http://www.codeproject.com/Articles/140911/log4net-Tutorial

    Roar Jørstad aka sveroa
    Senior Consultant, EVRY as
    Blog: Notebook, trick & tips
    Please mark as answer or helpful if my post is useful

    Wednesday, October 17, 2012 10:25 PM