Click here to Skip to main content
15,902,198 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I need to write a console application and enable logging in it. I have written Program and even loggng fnctionality using
C#
static class log
{
   public static void LogFile(string filename, string sExceptionMessage, string sexception,  string target, string temporary)
   {
      StreamWriter log;
      if (!File.Exists(temporary + "\\" + "Failed" + "\\" + "logfile.txt"))
      {
         log = new StreamWriter(temporary + "\\" + "Failed" + "\\" + "logfile.txt");
      }
      else
      {
         log = File.AppendText(temporary + "\\" + "Failed" + "\\" + "logfile.txt");
      }

      // Write to the file:
      log.WriteLine("Filename:" + filename);
      log.WriteLine("Data Time:" + DateTime.Now);

      log.WriteLine("Exception Message:" + sExceptionMessage);

      log.WriteLine("Exception:" + sexception);

      log.WriteLine("Target Site:" + target + Environment.NewLine + Environment.NewLine);

      // Close the stream:
      log.Close();
   }
}

but problem is my lead have asked me to write logging functioanlity using .Net logging framework.

Can someone help me with this.Which library is available in .net console for logging.
In Web application IIS functionality can be use but I have no idea in terma of Console.Please help.Does it mean Nlog or some external libraries .any suggestion?

Thanks in advance
Posted
Updated 26-Aug-14 6:01am
v3
Comments
[no name] 26-Aug-14 11:06am    
And your lead is not able to help you with this for some reason?
vicvis 26-Aug-14 11:13am    
actually time constraints with him and me also.I have written working code but need to modify if possible within time frame. unfortunately 1 day itself.
ZurdoDev 26-Aug-14 11:52am    
1. Reply to comment so that the user is notified.
2. What in the world does your lead mean? Log it to event log? Log to file? Log to db? You need to ask them what they mean.
vicvis 26-Aug-14 12:02pm    
ohk..thanks alot.I asked him,he wants a log file.is any .net framwork lib is available .I though of using NLog for same.Any comments?
ZurdoDev 26-Aug-14 12:04pm    
Log4Net is one I know a lot of people have used. I only write to a file when trying to write to the db has failed so I just use simple File.AppendAllText(). Very easy.

use Log4net
log4net Tutorial[^]
I have used it and found good.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Aug-14 13:29pm    
5ed.
—SA
vicvis 27-Aug-14 3:03am    
Thanks a lot
You can log to the event viewer.
Here are some examples -
Writing to System Event Log[^]
How to write to an event log by using Visual C#[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Aug-14 13:29pm    
5ed.
—SA
Abhinav S 26-Aug-14 22:52pm    
Thank you SA.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900