Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# console log file

C# console log file

Scheduled Pinned Locked Moved C#
csharptutorialquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sc steinhayse
    wrote on last edited by
    #1

    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?

    F L J V 4 Replies Last reply
    0
    • S sc steinhayse

      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?

      F Offline
      F Offline
      fjdiewornncalwe
      wrote on last edited by
      #2

      It's a little too big a solution to do in a single post, so I'll link you to a good CP article that will give you a full solution. log4net Tutorial[^]

      I wasn't, now I am, then I won't be anymore.

      1 Reply Last reply
      0
      • S sc steinhayse

        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?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You can pipe the stdout to a file, like this (run from console)

        C:\> MyProgram.exe >C:\Temp\MyFile.txt

        Also works from Windows-shortcuts.

        Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

        1 Reply Last reply
        0
        • S sc steinhayse

          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?

          J Offline
          J Offline
          jschell
          wrote on last edited by
          #4

          If the following is true. 1. ONLY log output is written (presumably the case) 2. You can change the code Then you might want to try using the System.Console.SetOut() method. You can provide your own writer which you can then put the data anywhere you want.

          1 Reply Last reply
          0
          • S sc steinhayse

            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?

            V Offline
            V Offline
            V 0
            wrote on last edited by
            #5

            If you can change the code you can basically change all Console.WriteLine("") to a log function. Example:

            public void WriteLog(string logtext){
            StreamWriter writer = new StreamWriter("[path here]", true);
            writer.writeLine(DateTime.Now.ToString() + ": " + text);
            writer.Close();
            }

            hope this helps.

            V.
            (MQOTD Rules )

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups