Link to home
Start Free TrialLog in
Avatar of Aquarus
Aquarus

asked on

Create Log File

In  C3 Windows Form application I would like to create the method, I would call Write2Log where I will be writing my exceptions in a manner Write2Log(ex.Message);
References I am using in my applications are:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;
using System.Deployment.Application;

Help me with  a code.  

           


           
ASKER CERTIFIED SOLUTION
Avatar of libin_v
libin_v
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Attached is simple method of logging.
using System.IO;
......
 
    public static void Write2Log(String logMessage)
    {
        using (StreamWriter w = File.AppendText("log.txt"))
        {
        w.Write("\r\nLog Entry : ");
        w.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),
            DateTime.Now.ToLongDateString());
        w.WriteLine("  :");
        w.WriteLine("  :{0}", logMessage);
        w.WriteLine ("-------------------------------");
        // Update the underlying file.
        w.Flush(); 
        w.Close();
        }
    }

Open in new window

oops, forgot to refresh browser...
Avatar of Aquarus
Aquarus

ASKER

I received the following error:

The type or namespace name 'ArrayList' could not be found (are you missing a using directive or an assembly reference?)      
What references am I missing?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial